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)
DEFINT ASIZE = SIZEOF(newArray)
DEFINT s(1 TO 5) = {9,5,3,3,1}, MAX = container.size/ASIZE, __step
PRINT "ORDENANDO..";" "; MAX
FOR i%=1 TO UBOUND(s)
j% = 1
__step = s(i%)
DO
save% = j%
DO
k% = j%
INC j%, __step
IF j% > MAX THEN
EXIT DO
END IF
container.position = (k%-1)*ASIZE
container.readUDT(newArray)
container.position = (j%-1)*ASIZE
container.readUDT(u)
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%
IF (MAX-j%) < __step THEN
EXIT DO
END IF
LOOP
NEXT
viewit
SUB viewit
FOR l%=1 TO MAX
container.position = (l%-1)*ASIZE
container.readUDT(newArray)
PRINT newArray.Key; " "; newArray.item
NEXT
END SUB
|