Solved

another queue question...

Posted on 2000-04-27
2
195 Views
Last Modified: 2010-04-15
what do the initially empty stacks Q and T look like after the sequence of statements: Q.Push(1,Success); Q.Push(2,Success); T.Push(3,Success); T.Push(4,Success); Q.GetStackTop(Stacktop,Success); T.Push(Stacktop,Success); Q.Pop(Success); T.Push(5,Success); Q.Push(6,Success);

i want to say it is Q=6,2,1;T=5,2,4,3

am i right??
0
Comment
Question by:beachbumm
2 Comments
 
LVL 16

Accepted Solution

by:
imladris earned 10 total points
ID: 2755614
This is a stack actually. Similar situation. I assume that Push pushes the first argument onto the stack. Pop pops the stack, and GetStackTop gets the top element of the stack back in the first argument (StackTop in this case) without changing the stack.

Q:
T:

Q.Push(1,success);
Q.Push(2,success);

Q: 1, 2
T:

T.Push(3,success);
T.Push(4,success);

Q: 1, 2
T: 3, 4

Q.GetStackTop(StackTop,success);

Q: 1, 2
T: 3, 4
and StackTop is 2

T.Push(StackTop,success);

Q: 1, 2
T: 3, 4, 2

Q.Pop(success);

Q: 1
T: 3, 4, 2

T.Push(5,success);
Q.Push(6,success);

Q: 1, 6
T: 3, 4, 2, 5

So yes, in fact stacks are very similar to queues. They are normally thought of oriented vertically rather than horizontally, but that is harder to type. The main difference is that a Pop takes off the last element added, whereas a Delete (for a queue) takes of the first element that was added. A queue is a FIFO queue (first in, first out), whereas a stack is a LIFO (last in, first out) queue.
Looks like we got the same answer (your stack top was on the "other" side), except for the Pop.
What do you think?
0
 

Author Comment

by:beachbumm
ID: 2755678
i agree with you on this...i guess i still had a queue working in my mind not a stack! thanks again!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why adding test code changes the build ? 11 132
Adjust Mfcapp 29 172
In C, why can't I shift a 64-bit integer more than 32 bits? 13 249
A  &&  B  || (C||D) how it works in c 7 101
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question