Tuesday, March 5, 2019

DIFFERENCE BETWEEN STACK AND QUEUE

          Stack and queue both are the non primitive data structures. the main difference between stack and queue are that stack uses LIFO method to access and add data elements whereas Queue uses FIFO method to access and add data elements.
                                        

S.NO
                     
           STACK
                    
            QUEUE



     1

Stack is an ordered list where in all insertion and deletions are performed at one end called top.

Queue is an ordered list where insertion are performed at rear end and deletion are performed at front end.
      

     2
 Associated with stack there is one variable called top initially top=-1 indicates stack is empty.
Associated with queue there are two varriables called front & rear. Initially front=0 & rear=-1 indicates queue is empty if (front>rear). 
       

     3

 Stack is full can be represented by the condition 
top=max_size-1.

Queue is full can be represented by the condition rear=max_ queue-1.


   4


 Stack is called Last In First Out(LIFO) structure.


Queue is called First In First Out(FIFO) structure.

   5

It does not have variants.

It has variants like circular queue,priority queue, dounly ended queue.


    6

Operations performed on stack are pop and push.

Operations performed on stack are enqueue and dequeue. 

No comments:

Post a Comment