Español
Fuente/ Codesnippets

Speicherminimaler Teilsort para Integerarrays: Der Singleton-Algorithmus

 

p.specht

Zugegeben, heutzutage es Speicherminimierung en Rechnern kaum sinnvoll, en Embeded Systems (Microprozessoen en Autos, Waschmaschinen, IoT-Geräten etc.) se allerdings siempre todavía grosser Valor darauf gelegt. Dazu hier una bastante populärer Algorithmus, natürlich como siempre como private XProfan-11-Demo sin Gewähr...El Rechte mentira en ACM.

Anmerkung: Enthält una el einfachsten Pseudozufallsgeneratoren, el lo son. Aus mathematischer Sicht grottenschlecht, para praktische Verhältnisse aber durchaus geeignet.
Título de la ventana upper$("Singleton-Sort uno Integer-Vektors zwischen Index ii y jj")
' (D) DEMO TRANSLATION from Fortran77 to XProfan11.2a en 2014-11
' by P. Pájaro carpintero, Wien (Austria); Ohne jedwede Gewähr! No warranties whatsoever!
'*******************************************************************************
' An Efficient Algorithm for Sorting with Minimal Storage, by: R. C. Singleton
' ALGORITHM 347, COLLECTED ALGORITHMS FROM ACM.
' THIS WORK PUBLISHED IN COMMUNICATIONS OF THE ACM
' VOL. 12, NO. 3, March, 1969, PP.185--187.
'*******************************************************************************
' SORTS ARRAY A INTO INCREASING ORDER, FROM A(II) TO A(JJ).
' ORDERING IS BY ***INTEGER SUBTRACTION***, THUS FLOATING POINT
' NUMBERS MUST BE IN NORMALIZED FORM!
' ARRAYS IU(K) AND IL(K) PERMIT SORTING UP TO 2^(K+1)-1 ELEMENTS.
'*******************************************************************************
Ventana de Estilo 24:font 2
Ventana 0,0-%maxx,%maxy

Proc SingletonSORT :parámetros A&[],ii&,jj&

    DECLARE iJ&,il&[16],iu&[16],j&,k&,l&,m&,t&,tt&
    M& = 1
    I& = II&
    J& = JJ&
    G5:
    CASE I& >= J&: GOTO "G70"
    G10:
    K& = I&
    IJ& = (J&+I&)/2
    T& = A&[IJ&]
    caso A&[I&]<=T&:GOTO "G20"
    A&[IJ&] = A&[I&]
    A&[I&] = T&
    T& = A&[IJ&]
    G20:
    L& = J&
    caso A&[J&] >= T& : GOTO "G40"
    A&[IJ&] = A&[J&]
    A&[J&] = T&
    T& = A&[IJ&]
    caso A&[I&] <= T& : GOTO "G40"
    A&[IJ&] = A&[I&]
    A&[I&] = T&
    T& = A&[IJ&]
    GOTO "G40"
    G30:
    A&[L&] = A&[K&]
    A&[K&] = TT&
    G40:
    L& = L& - 1
    caso A&[L&] > T& : GOTO "G40"
    TT& = A&[L&]
    G50:
    K& = K& + 1
    caso A&[K&] < T& : GOTO "G50"
    caso K& <= L&: GOTO "G30"
    caso (L&-I&) <= (J&-K&): GOTO "G60"
    IL&[M&] = I&
    IU&[M&] = L&
    I& = K&
    M& = M& + 1
    GOTO "G80"
    G60:
    IL&[M&] = K&
    IU&[M&] = J&
    J& = L&
    M& = M& + 1
    GOTO "G80"
    G70:
    M& = M& - 1
    caso M& = 0 : RETORNO
    I& = IL&[M&]
    J& = IU&[M&]
    G80:
    caso (J&-I&) >= II& : GOTO "G10"
    caso I& = II& : GOTO "G5"
    I& = I& - 1
    G90:
    I& = I& + 1
    caso I& = J& : GOTO "G70"
    T& = A&[I&+1]
    caso A&[I&] <= T& : GOTO "G90"
    K& = I&
    G100:
    A&[K&+1] = A&[K&]
    K& = K& - 1
    caso T& < A&[K&] : GOTO "G100"
    A&[K&+1] = T&
    GOTO "G90"

ENDPROC

Proc RN' uses seed&

    declarar k&,rn! : caso seed&=0:seed=rnd()
    '*******************************************************************************
    '  RN returns a unit single precision pseudorandom number.
    '*******************************************************************************
    '
    '  This routine implements the recursion
    '
    '      seed = 16807 * seed mod ( 2^31 - 1 )
    '      rn = seed / ( 2**31 - 1 )
    '
    '    The integer arithmetic never requires more than 32 bits, including a sign bit.
    '
    '    If the initial seed is 12345, then the first three computations are
    '
    '      Entrada     Output      RN
    '      SEED      SEED
    '
    '         12345   207482415  0.096616
    '     207482415  1790989824  0.833995
    '    1790989824  2035175616  0.947702
    '
    '  Modified: 11 August 2004, Author: John Burkardt
    '
    '  Reference:
    '
    '    Paul Bratley, Bennett Fox, L E Schrage,
    '    A Guide to Simulation,
    '    Springer Verlag, pages 201-202, 1983.
    '
    '    Pierre L'Ecuyer,
    '    Random Number Generation,
    '    en: Handbook of Simulation,
    '    edited by Jerry Banks,
    '    Wiley Interscience, page 95, 1998.
    '
    '    Bennett Fox,
    '    Algorithm 647:
    '    Implementation and Relative Efficiency of Quasirandom
    '    Sequence Generators,
    '    ACM Transactions on Mathematical Software,
    '    Volume 12, Number 4, pages 362-376, 1986.
    '
    '    P A Lewis, A S Goodman, J M Miller,
    '    A Pseudo-Random Number Generator for the Sistema/360,
    '    IBM Systems Journal,
    '    Volume 8, pages 136-143, 1969.
    '
    '  Parámetros:
    '
    '    Entrada/output, integer SEED, the "seed" value, which should NOT be 0.
    '    On output, SEED has been updated.
    '
    '    Output, real RN, a new pseudorandom variate,
    '    strictly between 0 and 1.
    '
    k& = seed& \ 127773
    seed& = 16807 * ( seed& - k& * 127773 ) - k& * 2836

    if seed& < 0

        seed& = seed& + 2147483647

    endif

    '  Although SEED can be represented exactly as a 32 bit integer,
    '  it generally cannot be represented exactly as a 32 bit real number'
    rn! = seed& * val("4.656612875E-10")
    volver rn!

ENDPROC

' MAIN tests SORT.
' Modified 04 January 2006 by John Burkardt
Imprimir "\n\n TOMS347_PRB\n Test Singleton Sort, which sorts a integer vector ascending."
declarar ii&,jj&
ii& = 1
jj& = 20
test01(ii&,jj&)
waitinput
ii& = 5
jj& = 18
test01(ii&,jj&)
imprimir "\n TOMS347_PRB: Success - Normal end of execution!"
waitinput
end

Proc test01 :parámetros ii&,jj&

    '*******************************************************************************
    '  TEST01 tests SORT on a particular range of indices.
    '  Modified 04 January 2006 by John Burkardt
    '*******************************************************************************
    var n&=20
    declarar a&[n&],i&,rn!,seed&
    Imprimir "\n\n TEST01: Ascending sorts a integer vector."
    Imprimir " Here we sort entries II = ";ii&;" to JJ = ";jj&
    seed& = 123456789

    whileloop n& : i&=&Loop

        a&[i&] = int(n&*RN(seed&))

    endwhile

    Imprimir "\n Unsorted array:"

    whileloop n&:i&=&Loop

        imprimir i&, a&[i&]

    endwhile

    SingletonSORT(a&[],ii&,jj&)
    Imprimir "\n Sorted array:"

    whileloop n&:i&=&Loop

        imprimir i&, a&[i&]

    endwhile

ENDPROC

''TOMS347_PRB  RESULTS OF Test SORT, which ascending sorts a integer vector.
'
'TEST01
'  SORT ascending sorts a integer vector.
'  Here we sort entries II =      1
'  through JJ =     20
'
'  Unsorted array:
'
'       1       4
'       2      19
'       3      16
'       4      11
'       5       8
'       6       1
'       7       5
'       8       2
'       9       0
'      10      12
'      11       1
'      12       8
'      13       8
'      14      15
'      15      15
'      16       0
'      17      17
'      18       7
'      19       1
'      20       0
'
'  Sorted array:
'
'       1       0
'       2       0
'       3       0
'       4       1
'       5       1
'       6       1
'       7       2
'       8       4
'       9       5
'      10       7
'      11       8
'      12       8
'      13       8
'      14      11
'      15      12
'      16      15
'      17      15
'      18      16
'      19      17
'      20      19
'
'TEST01
'  SORT ascending sorts a integer vector.
'  Here we sort entries II =      5
'  through JJ =     18
'
'  Unsorted array:
'
'       1       4
'       2      19
'       3      16
'       4      11
'       5       8
'       6       1
'       7       5
'       8       2
'       9       0
'      10      12
'      11       1
'      12       8
'      13       8
'      14      15
'      15      15
'      16       0
'      17      17
'      18       7
'      19       1
'      20       0
'
'  Sorted array:
'
'       1       4
'       2      19
'       3      16
'       4      11
'       5       0
'       6       0
'       7       1
'       8       1
'       9       2
'      10       5
'      11       7
'      12       8
'      13       8
'      14       8
'      15      12
'      16      15
'      17      15
'      18      17
'      19       1
'      20       0
 
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
17.05.2021  
 



Zum Quelltext


Título del Tema, max. 100 Signo.
 

Systemprofile:

Kein Systemprofil creado. [anlegen]

XProfan:

 Contribución  Font  Smilies  ▼ 

Bitte registro en una Contribución a verfassen.
 

Tema opciones

830 Views

Untitledvor 0 min.
Ernst21.07.2021
Uwe ''Pascal'' Niemeier13.06.2021
R.Schneider04.06.2021
Michael W.28.05.2021
Más...

Themeninformationen

Dieses Thema ha 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Autores  |  Chat  |  Política de Privacidad  |  Descargar  |  Entrance  |  Ayuda  |  Merchantportal  |  Pie de imprenta  |  Mart  |  Interfaces  |  SDK  |  Services  |  Juegos  |  Búsqueda  |  Support

Ein Projekt aller XProfan, el lo son!


Mi XProfan
Privado Noticias
Eigenes Ablageforum
Temas-Merkliste
Eigene Beiträge
Eigene Temas
Zwischenablage
Cancelar
 Deutsch English Français Español Italia
Traducciones

Política de Privacidad


Wir uso Cookies sólo como Session-Cookies wegen el technischen Notwendigkeit y en uns hay no Cookies de Drittanbietern.

Wenn du hier en unsere Webseite klickst oder navigierst, stimmst du unserer Erfassung de Informationen en unseren Cookies en XProfan.Net a.

Weitere Informationen a unseren Cookies y dazu, como du el Kontrolle darüber behältst, findest du en unserer nachfolgenden Datenschutzerklärung.


einverstandenDatenschutzerklärung
Yo möchte no Cookie