Sorting with maps? how?
Monkey Forums/Monkey Programming/Sorting with maps? how?
| ||
| hey, i wanted to try out the new NextNode stuff from maps, wich came with 78h i tryed it like this: (sort the strings by numbers (Int as key) Edit: it works now, sorry for bugging, the following code is works fine:
Local map:Pmap = New Pmap
map.Insert(1, "1 une")
map.Insert(5, "5 fyve")
map.Insert(2, "2 twoo")
map.Insert(4, "4 four")
map.Insert(3, "3 drey")
Local node:= map.FirstNode() ' i also tried Local node:map.Node<Int,String> (same result)
node = map.FirstNode()
While map.Count() > 0
Print node.Value
node = node.NextNode()
map.Remove(node.Key) 'i forget this! =)
Wend
its shooted me a MAV (even with debug on glfw) in the code of map.Firstnode, but now it works fine pmap is just an extend of map with the sort stuff added: Class Pmap Extends Map<int, String> Method Compare:Int(lhs:Int, rhs:Int) Return lhs - rhs End Method End Class |
| ||
| lol ok it works, i just forget to add the removing of keys. i forgot to do map.Remove(node.Key), and so i had a getting of next when there is no next :) sorry for bugging, it seems i allways find errors wich i seeking like an hour when i just write them down into the forum, hehe |