'How to create object of stack node with a name that increases using a for loop
So I need to make a Queue that has Stacks associated with each index. Now the program I have will use the user's specific commands (will do some things) and then those commands modify the size of the Queue and the size of each Stack at each index of the Queue. Both Stack and Queue are node-based.
Essentially I want a loop to create a new Stack at the index of a new Queue (when the user enqueues) and to be able to modify that stack at that Queue. I am new to coding so if there is a better way I do appreciate the help but there is more to this code and I just need help with this bit for now.
let's say queue size is 4
for i in range(Queue.size)
s[i] = stack
s0.push(a)
s0.push(b)
s1.push(c)
s2.push(d)
s2.push(e)
s0.push(f)
This has an effect of such
Queue = A -> B -> C -> NONE
| | |
f e d
b d
a
s0 s1 s2
Now that for loop doesn't work because it is a string and can't work with Stack. I need to find a way to make this work or another way in which a similar effect can be accomplished. I've scoured the web for a week and can not find an answer. Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
