Forming a list where the relative positions of item are preset

cloa513

  • Posts: 245
This shouldn't complicated but can't think how to do it. List items are added one at time and items with an associated number of 2 need to go after item 1 and so forth with any number items of a given number- the actual number of items with an associated number is unlimited. So say nine associated numbers 0 to 8. For example X with 2, Y with 3, Z with 3, D with 4, E with 4 will produce
a list of (X,Y,Z,D,E) - can have any number of Null values.  What is the simplest way to do this?  Its preferable to not have list sorting.

BMJ

  • Posts: 278
As I understand it, you can't have more than one of each index (the number) in a list. (But you could make a 2D list with the 2D List extension. Then, each index could be its own list of items. In other words ...

Your Master List
=============
Index | Value
0           | (contains a list of ordered items. In your example, this list would be empty.)
1           | (contains a list of ordered items. In your example, this list would  be empty.)
2           | (contains a list with item X)
3           | (contains a list with items Y and Z)
4           | (contains a list with items D and E)

If you wanted to avoid the ordering of items in the sublist, you could create some logic that randomizes the order of all the items in the sublist at index "3", for example, so that Y and Z  wouldn't always print out in the same order, if that's what you wanted.

cloa513

  • Posts: 245
Thanks for your reply.
Yes but I don't really want to have a 2D list- it just needs to be processed from top to bottom- 2D list extension requires choose the size before you start so it would possibly enormous (another solution for a normal list involves an enormous list) and doesn't have any means to simply go from the top left item and right then  to the first on the next row with neat code. Each item will have a new index and the absolute position doesn't matter only the relative position. My latest thought is this have a primary  List1 and  a secondary List2 that has elements from 0 to 8 which represents the row numbers of the spaces available. You can set items in List1 to the associated number of the row - if that row has a value then you insert the item at that row and then take List2 and increment each item at row number below the current to the last item.
i.e. Following my original example ( the item may not be added in any order)
Updates of List attributes
List1: (-,-,X,-,-,-,-,-,-)
List1: (-,-,X,Y,-,-,-,-,-)
List1 (-,-,X,Y,Z,-,-,-,-,-)
List2 (0,1,2,3,4,6,7,8,9)
and so on. If you can think of simpler code - it would be much appreciated.