Question:
What is a stack and a queue?(data structure)?
?
2010-11-12 11:38:48 UTC
what is a stack and queue talking about data structure?
Four answers:
oops
2010-11-12 11:51:17 UTC
They are special types of lists that differ in how elements are added and removed.



A stack utilizes the LIFO rule. (L)ast (I)n (F)irst (O)ut. That means you put elements in at the top, and remove them from the top, just like a real life stack (of dinner plates for example).



A queue utilizes FIFO. (F)irst (I)n (F)irst (O)ut. Elements are inserted at one end, but can only be removed from the other end. Just like a real life queue (a line at the bank for example)
2010-11-12 11:53:33 UTC
A stack is a list in which all insertions and deletions are made at one end, called the top. The last element to be inserted into the stack will be the first to be removed. Thus stacks are sometimes referred to as Last In First Out (LIFO) lists.



A Queue is an ordered collection of items from which items may be deleted at one end (called the front of the queue) and into which items may be inserted at the other end (the rear of the queue).



Want more detailed explanation? Take a look at this : http://isg.cs.tcd.ie/giangt/Stack-Queue.pdf







♫ ♪ ♪ ♫
2016-04-22 18:00:07 UTC
I'll tell you how to do it: You have stacks A and B that you are trying to take the union of. You'll need a third stack C that you'll hold the union on. Pop stack A and B, check which one is smaller, and push that onto stack C. Then which ever stack had the smaller value, pop it and repeat the process. Keep doing this until both A and B are empty. Now you have the union in C, but it is in reverse order. So get another empty stack D(or reuse A or B), and Pop C and push that onto D, repeat this until C is empty, and now you have the union in D
2010-11-12 12:02:48 UTC
go to this website there some lecture notes and (data structures )


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...