Stack consisting of stacks?

I need to use a stack consisting of stacks for an assignment. I declared it the following way:
 
stack <stack<int>> table;

and when I compiled it, it ran with no error,
but my question is how can I decide on which stack will an element be pushed in because
 
table.push(i)

doesn't work, nor anything else I try does.
You need to add at least one stack to your table before you can push anything.
1
2
3
4
5
6
  stack<stack<int>> table;

  stack<int> first_stack;

  table.push(first_stack);
  table.top().push(10); // insert 10 into the top stack 


I never came across a stack of stacks. Can you post the complete assignment?
I'm replying sort of late because I hadn't logged in here for a few days, but I'll post the assignment. (btw, it might sound a little strange, because I'll be translating from my mother tongue, but I am able to explain it completely)

On a table, there are N cubes, where 1<=N<=100. A line of commands moves the cubes. Each command consists of 2 integers, A and B, and it means that cube A is moved on cube B. For example, the command 1 3 means that cube 1 is moved on cube 3. The top of the table is symbolized with the number 0, so in result, the command 7 0 should move cube 7 on the table and not on a cube.

The following criteria must apply:
If cube A has a stack of cubes on it, then the stack remains on top of the cube, and is moved along with A to B.

If cube B has a stack of cubes on top of it, then that stack is moved on the table, so there won't be a cube on B and only then cube A (with, or without cubes on it) is moved on B.

Here's a picture that is included with the assingment and I thought it might be needed to understand the procedure completely:

http://i.imgur.com/MUR7nT7.png

Input format:

First line consists of an integer N, and the following lines, consist of command input with 2 integers. The program should run until the user enter 0, 0 as an input.

Output format:
The final state of all the cubes(meaning it should show all the cubes above each cube)

Example(this is the example shown in the picture above also)
Input:
5
3 1
5 3
3 4
2 3
3 0
4 2
0 0

Output:
1:
2: 4
3: 2 4
4:
5:
Last edited on
Topic archived. No new replies allowed.