You are on page 1of 2

In your own words, describe the structure and function of both the stack and

queue data structure and discuss how they are different from the perspective of
how they are used.

Stack:
Stack is a linear data structure in which data may be inserted and removed from
only one end. It follows the principle of LIFO(Last-In-First-Out). LIFO means the
data which enter at last will remove first. I can add an example of lift. In lift, the
last person who enters, he will out of the lift first. Basically we use the function
push to push a data into the stack and use pop function to remove the data. The
accessible element of the stack is called the top element. We use different
variation of the stack implementation. Two basic implementations are Array-
Based Stack and Linked Base (P.117,textbook).

(www.studytonight.co
m)

Queue:
Queue is also a linear data structure in which data may be inserted and removed
from two ends. It follows the principle of FIFO(First-In-First-Out). LIFO means the
data which enter at first will remove first. Queue elements may only be inserted
at the back which is called enqueue and remove from the front which is called
dequeue. For example, in a queue where people line up to pay for their groceries
at their local convenience store, the first person in the queued line will be served
first and will be the first one out, it will work for others in the line. The Queue can
be implemented using Array-Based and Linked (P.125, textbook).

(www.studytonight.com)

The basic difference between stacks and queues is in removing. In a stack we


remove the item the most recently added; in a queue, we remove the item the
least recently added. Stack is one ended whereas the queue is double ended.
Stack has insertion and deletion in one end only. Queue has insertion in one end
and deletion from other.

References:
Our text book
https://www.studytonight.com/data-structures/queue-data-structure

You might also like