Is it possible to sort a skiplist based on their key values? Currently, when I insert items into a skiplist, they are not coming out in the same order they went in. Instead, it comes out jumbled. For example, if I add the numbers 1 through 10 to a skipList in order, when I loop through the same skip using for dataElement in skipList, they are displayed back to me in a jumbled order. It might be: 3, 9, 7, 2, 1, 5, 10, 8, 4, 6.
Chris chrscote - Tue Mar 06 11:15:18 EST 2018 |
Re: How to sort skipLists Using a createString() skip the keys will sort alphabetically if that helps. This code:
Skip lSkip = createString()
put(lSkip, "c", "1")
put(lSkip, "d", "2")
put(lSkip, "e", "3")
put(lSkip, "b", "4")
put(lSkip, "a", "5")
string lVal
for lTmp in lSkip do{
string lKey = (string key lSkip)
print lKey "\n"
}
Will always output as: |
Re: How to sort skipLists davidcs - Tue Mar 06 11:39:24 EST 2018 Using a createString() skip the keys will sort alphabetically if that helps. This code:
Skip lSkip = createString()
put(lSkip, "c", "1")
put(lSkip, "d", "2")
put(lSkip, "e", "3")
put(lSkip, "b", "4")
put(lSkip, "a", "5")
string lVal
for lTmp in lSkip do{
string lKey = (string key lSkip)
print lKey "\n"
}
Will always output as: CreateString will sort in alphabetical order, yes, but also the "normal" create Skip should be ordered if you use integers as keys. The problem with alphabetical ordering is that if you use numbers as keys, then 10, 11 and so on will be ordered before 2. Try the following out with "create" Skip or "createString" Skip.
|
Re: How to sort skipLists PekkaMakinen - Wed Mar 07 01:02:04 EST 2018 CreateString will sort in alphabetical order, yes, but also the "normal" create Skip should be ordered if you use integers as keys. The problem with alphabetical ordering is that if you use numbers as keys, then 10, 11 and so on will be ordered before 2. Try the following out with "create" Skip or "createString" Skip.
And a proof that the integer skip list is really ordered by the key value
|