Slicing lists

BlitzMax Forums/BlitzMax Beginners Area/Slicing lists

Arowx(Posted 2005) [#1]
Hi,

I'm just writing a simple hi score table and found that what I would really like is a way to remove all items from the list over a certain size limit.

I realise that I could just loop through removing the last elements until the lists size was reduced however I got to thinking...

As a list is made of of links, all I should have to do is remove the link at the desired count position in such a way as to slice the list, I can't seem to see a way of doing this although my assumption is that it should be possible and would be nice to divide up lists?

Thank You


ImaginaryHuman(Posted 2005) [#2]
Are lists connected by both directions, ie previous item and next item? If so you'll have to sevver two ties.

As to the item to choose, you could keep track of which was the bottom item on the list by storing it in another variable ? if you could somehow know that while you're creating it. Presumably you are using a linked list because your list is created in random order and chopped about? Otherwise you should use an array.


Arowx(Posted 2005) [#3]
As the list in question is just a Hi Score list, I just went via the removeLast() method to trim it down to the desired size.

I think that dividing lists could be usefull, not sure what for exactly as you are probably sorting or dividing up the list in some way so maybe a binary tree would be more usefull as a data structure.

Cheers Merx


Perturbatio(Posted 2005) [#4]
If you absolutely need to slice them, then you can do so by converting them to an array (using the provided method), slice that, then convert back. (it's obviously going to be slower).