A
alan
Hello all, would just like to ask what would be the best reorderable
list structure.
Basically, I have to keep track of the order of some objects. The
most recently referred object would be in the top of the list. If an
object is referred to, and it isn't at the top of the list, it is put
to the top of the list and the other objects moved down:
1 omega
2 alpha
3 beta <- referred to
4 gamma
then:
1 beta
2 omega
3 alpha
4 gamma
At periodic times, I would then promote an object to the second-
topmost of the list (but not the first, since only the most recently
referred object must be at the top). This will usually be the
bottommost element of the list, but *not* always.
For example:
1 beta
2 omega
3 alpha
4 gamma <- I choose this for promotion
then:
1 beta
2 gamma
3 omega
4 alpha
Basically I need a list structure where I can rearrange particular
list members to the top or second position, with everyone moving
downwards correspondingly.
I've looked at std::slist, which provides splice_after which will work
with my second requirement (I think) but it doesn't seem to be able to
do the first requirement. Or should I look at std::list instead? Or
another container class?
---
In case you're curious about the application, I have a set of 3
affinities (and would like to keep open the possibility of future
affinities). The player may exercise an affinity to eventually
increase it, but if an affinity is increased by exercise, another
affinity must decrease.
Whenever an affinity is exercised, it is put to the top of the list.
The least recently exercised affinity then drifts to the bottom. When
the affinity being exercised is finally increased, the least recently
exercised nonzero affinity is decremented and put at the second
position on the list. By putting it on the second position when it is
decremented, if the player concentrates on one affinity only, each of
the other affinities are penalized equally until it becomes zero, at
which point the remaining affinities are the only ones affected.
list structure.
Basically, I have to keep track of the order of some objects. The
most recently referred object would be in the top of the list. If an
object is referred to, and it isn't at the top of the list, it is put
to the top of the list and the other objects moved down:
1 omega
2 alpha
3 beta <- referred to
4 gamma
then:
1 beta
2 omega
3 alpha
4 gamma
At periodic times, I would then promote an object to the second-
topmost of the list (but not the first, since only the most recently
referred object must be at the top). This will usually be the
bottommost element of the list, but *not* always.
For example:
1 beta
2 omega
3 alpha
4 gamma <- I choose this for promotion
then:
1 beta
2 gamma
3 omega
4 alpha
Basically I need a list structure where I can rearrange particular
list members to the top or second position, with everyone moving
downwards correspondingly.
I've looked at std::slist, which provides splice_after which will work
with my second requirement (I think) but it doesn't seem to be able to
do the first requirement. Or should I look at std::list instead? Or
another container class?
---
In case you're curious about the application, I have a set of 3
affinities (and would like to keep open the possibility of future
affinities). The player may exercise an affinity to eventually
increase it, but if an affinity is increased by exercise, another
affinity must decrease.
Whenever an affinity is exercised, it is put to the top of the list.
The least recently exercised affinity then drifts to the bottom. When
the affinity being exercised is finally increased, the least recently
exercised nonzero affinity is decremented and put at the second
position on the list. By putting it on the second position when it is
decremented, if the player concentrates on one affinity only, each of
the other affinities are penalized equally until it becomes zero, at
which point the remaining affinities are the only ones affected.