Guidance
指路人
g.yi.org
software / rapidq / Examples / Algorithm & Maths / mixed array.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From:   "Manuel Candela" Date:  Tue Jun 17, 2003  11:46 pm
' RapidQ doesn't accept mixed arrays. But with a UDT and a stream,
'such a structure can be simulatad.

     DECLARE SUB viewit

     STRUCT UDA
      key AS LONG
      item AS STRING*30
     END STRUCT

     DIM container AS QMEMORYSTREAM
     DIM newArray AS UDA, u AS UDA

     newArray.key = 10
     newArray.item = "aaaa"
     container.WriteUDT(newArray)

     newArray.key = 9
     newArray.item = "cccc"
     container.WriteUDT(newArray)

     newArray.key = 8
     newArray.item = "ffff"
     container.WriteUDT(newArray)

     newArray.key = 7
     newArray.item = "bbbb"
     container.WriteUDT(newArray)

     newArray.key = 6
     newArray.item = "ddddd"
     container.WriteUDT(newArray)

     newArray.key = 5
     newArray.item = "eeee"
     container.WriteUDT(newArray)

     newArray.key = 4
     newArray.item = "gggg"
     container.WriteUDT(newArray)

     newArray.key = 3
     newArray.item = "jjjj"
     container.WriteUDT(newArray)

     newArray.key = 2
     newArray.item = "iiii"
     container.WriteUDT(newArray)

     newArray.key = 1
     newArray.item = "hhhh"
     container.WriteUDT(newArray)

'Sort
     DEFINT ASIZE = SIZEOF(newArray)
     DEFINT s(1 TO 5) = {9,5,3,3,1}, MAX = container.size/ASIZE, __step

     PRINT "ORDENANDO..";" "; MAX

'Shell's sort method
     FOR i%=1 TO UBOUND(s)
      j% = 1
      __step = s(i%)

'print __step
      DO
       save% = j%
       DO
        k% = j%
        INC j%, __step
        IF j% > MAX THEN
         EXIT DO
        END IF

'Read and test
        container.position = (k%-1)*ASIZE
        container.readUDT(newArray)
        container.position = (j%-1)*ASIZE
        container.readUDT(u)

'print k%; newarray.item; j%; u.item
        IF newArray.item > u.item THEN
         container.position = (k%-1)*ASIZE
         container.WriteUDT(u)

         container.position = (j%-1)*ASIZE
         container.WriteUDT(newArray)
        END IF
       LOOP

       j% = save% : INC j%
'print j%; MAX; " Pass again .. same step."
       IF (MAX-j%) < __step THEN
        EXIT DO
       END IF
      LOOP

     NEXT

     viewit

'Show
     SUB viewit
      FOR l%=1 TO MAX
       container.position = (l%-1)*ASIZE
       container.readUDT(newArray)
       PRINT newArray.Key; " "; newArray.item
      NEXT
     END SUB
'------------------------------------

'Let us think of the numeric part as a line index and the words as values of
'some column, extracted from a chart of data -or something like that-. Some
'other ideas?..
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2009-07-25 17:30:54