Thanxx Charles
but when i modified the program as below, to sort the array in ascending order
it display a screen of elements that have blanks from index 1 to 7 as shown in the atteched screen shot?
i also added 2 new macros filterblanks and compareAO
how to eliminate these blank elements in the screen display?
'2018-03-28 T 11:03:11
'FILTERING AND SORTING
' http://www.oxygenbasic.org/forum/index.php?PHPSESSID=bbb1n9397c7uq6d0f1ft4vscr0&topic=1613.msg17561;topicseen#msg17561
' Sort_Array.o2bas
' NewSortIndex enables you to create indexes on any kind of data arrays,
' filtered by any criteria and sorted by any criteria.
uses generics
uses console
'CREATE SOME DATA
=================
string dat={"a2","a1","a","b","c","d","e","f","g","h","i","j"}
int ct = CountOf dat
int cf 'Count of Filtered Data
'CALLBACK MACROS FOR FILTERING AND INDEXING
' filter off those characters > than e
macro filter(accept,i)
======================
if asc(dat[i])<=0x65 then accept=1
end macro
' filter off blank characters
macro filterblanks(accept,i)
======================
if asc(dat[i])<>0x22 then accept=1
end macro
'DESCENDING ORDER macro
macro compareDO(swap,a,b)
=======================
if dat[a]<dat[b] then swap=1
end macro
'ASCENDING ORDER macro
macro compareAO(swap,a,b)
=======================
if dat[a]>dat[b] then swap=1
end macro
'------------------------------------------------------
' Main program starts here
' descending order
NewSortIndex idx,ct,cf,filter,compareDO
'SHOW RESULTS
=============
print "RAW DATA" cr
ListArray dat,print,ct
printl
print "FILTERED AND INDEXED DATA" cr
ListArray dat,print,cf,idx
printl
print "INDEX USED" cr
ListArray idx,print,cf
NewSortedData(sd,dat,idx,cf)
printl
print "SORTED DATA descending" cr
ListArray sd,print,cf
'DelSortIndex idx
'DelSortedData sd
' Now in Ascending order
NewSortIndex idx,ct,cf,filterblanks,compareAO
NewSortedData(sd,dat,idx,cf)
printl
print "SORTED DATA Ascending" cr
ListArray sd,print,cf
wait
DelSortIndex idx
DelSortedData sd