• Register
Welcome to the Question Answers about All Engineering Fields. Please use search option at the top right before asking questions.

Difference between stack and queue?

0 votes
Be the first
What are the main differences between stack and queue?
asked Jun 5, 2013 in Computer Engineering by Saba Khan  

2 Answers

+1 vote
Be the first
 
 

The difference between stack and queue is how they are removed. In a stack the last in will be the first one out (LIFO). In a queue it is first in is the first out (FIFO).

      

In a stack adding or deleting can only be done from the end called the top. In a queue adding is done at the end and removing is done from the front.

          

 

 
answered Jun 13, 2013 by sheebaaltaf  
0 votes
Be the first

Stack :

A stack can be compared to a bottle that is filled with stones. The only way to access the bottom stone is to remove the top stone one by one. So the stone that has gone in first is the last to come out .

Stack is a collection of objects that works in LIFO (Last in First out) mechanism while Queue is FIFO (First in First out). This means that the object that is inserted first is removed last in a stack while an object that is inserted first is removed first in a queue.

Queue :

A queue can be compared to a queue at a bus stop - people board the bus in the order they arrive to the bus stop and join the queue. So the first person to join the queue is the first person to board the bus.

A Queue is a first-in, first-out data structure that pops elements in the same order than they were pushed

 

 

 

 

 

 

answered Jun 13, 2013 by saif hassan  

Related questions

0 votes
Be the first
1 answer 1,316 views
+1 vote
Be the first
1 answer 297 views
0 votes
Be the first
1 answer 12 views
Welcome to All Engineering Questions Answers QnA, where you can ask questions and receive answers from other members of the community.
...