STACKS AND QUEUES
STACKS
• Stack is known as a linear data structure. It follows
the Last-In-First-Out rule.
• If you push something to the stack then the last
value which you pushed, will be the first to pop
out.
• The insertion and deletion operation on the stack
will only take place from one end which is the top
of the stack.
IMPLEMENTATION OF STACKS
1. Statically:- In C, you can implement a stack using an array. It
allows static memory allocation of its data elements. In this, the
stack inherits all the features of the array.
2. Dynamically:- You can also implement a stack using a linked list. It
allows dynamic memory allocation of its data elements. In this, the
stack takes over the characteristics of the linked list.
OPERATIONS ON STACKS
• Push: This function adds an element to the top of the Stack.
OPERATIONS ON STACKS
• Pop: This function removes the topmost element from the stack.
OPERATIONS ON STACKS
• Display : The stack data elements are displayed in the stack according
to the LIFO rule.
OPERATIONS ON STACKS
• Stack Overflow : Here we are talking about the static memory
allocation of data elements of a stack. Therefore, if the stack is filled
completely, that is, no more elements can be inserted in the stack, then
the condition would be called STACK-FULL condition. It is also
referred to as stack overflow.
• Stack Underflow : In case we wish to display the data elements of the
stack or perform the deletion operation, but no elements have been
inserted into the stack yet, this condition is called STACK-EMPTY. It
is also referred to as stack underflow.
APPLICATIONS OF STACKS
1. Number Reversing: You can easily reverse a sequence of characters
or digits.
2. Undo Operation: In text editors, you can see an undo operation. If
you click it then all the changes you made will go back to normal. All the
changes are stored into the stack.
3. Infix to Postfix Conversion: With the help of stacks, you can
convert from infix to postfix.
4. Backtracking: You can use stacks to solve various maze puzzling
problems.
5. Depth First Search: With the help of stacks, you can perform a
searching algorithm named Depth-First Search.
QUEUES
• Queue is known as a linear data structure. It follows the First-In-First-
Out rule.
• So, if you push something to the stack then the first value of the stack
will pop out.
• In the queue, the insertion operation is done from the rear end(back)
and the deletion is done from the front.
IMPLEMENTATION OF QUEUES
• Statically: Array implementation of queues allows the static memory
allocation of its data elements. It is important to note that in this
method, the queue acquires all the features of an array.
• Dynamically: Linked list implementation of queues follow the
dynamic memory allocation of its data elements. It is important to note
that in this method, the queue inherits all the characteristics of a linked
list.
OPERATIONS ON QUEUES
• Enqueue - adding an element in the queue if there is space in the
queue.
OPERATIONS ON QUEUES
• Dequeue- Removing elements from a queue if there are any elements
in the queue
OPERATIONS ON QUEUES
• Front - This function returns the front element of the queue.
• Size - This function returns the size of a queue or the number of
elements in a queue.
TYPES OF QUEUES
• The standard queue data structure has the following variations:
1. Double-ended queue
2. Circular queue
• Double-ended queue: In a standard queue, a character is inserted at
the back and deleted in the front. However, in a double-ended queue,
characters can be inserted and deleted from both the front and back of
the queue.
TYPES OF QUEUES
• Circular queues: A circular queue is an improvement over the
standard queue structure.
• In a standard queue, when an element is deleted, the vacant space is not
reutilized. However, in a circular queue, vacant spaces are reutilized.
• While inserting elements, when you reach the end of an array and you
need to insert another element, you must insert that element at the
beginning.

STACKS AND QUEUES.pptx

  • 1.
  • 2.
    STACKS • Stack isknown as a linear data structure. It follows the Last-In-First-Out rule. • If you push something to the stack then the last value which you pushed, will be the first to pop out. • The insertion and deletion operation on the stack will only take place from one end which is the top of the stack.
  • 3.
    IMPLEMENTATION OF STACKS 1.Statically:- In C, you can implement a stack using an array. It allows static memory allocation of its data elements. In this, the stack inherits all the features of the array. 2. Dynamically:- You can also implement a stack using a linked list. It allows dynamic memory allocation of its data elements. In this, the stack takes over the characteristics of the linked list.
  • 4.
    OPERATIONS ON STACKS •Push: This function adds an element to the top of the Stack.
  • 5.
    OPERATIONS ON STACKS •Pop: This function removes the topmost element from the stack.
  • 6.
    OPERATIONS ON STACKS •Display : The stack data elements are displayed in the stack according to the LIFO rule.
  • 7.
    OPERATIONS ON STACKS •Stack Overflow : Here we are talking about the static memory allocation of data elements of a stack. Therefore, if the stack is filled completely, that is, no more elements can be inserted in the stack, then the condition would be called STACK-FULL condition. It is also referred to as stack overflow. • Stack Underflow : In case we wish to display the data elements of the stack or perform the deletion operation, but no elements have been inserted into the stack yet, this condition is called STACK-EMPTY. It is also referred to as stack underflow.
  • 8.
    APPLICATIONS OF STACKS 1.Number Reversing: You can easily reverse a sequence of characters or digits. 2. Undo Operation: In text editors, you can see an undo operation. If you click it then all the changes you made will go back to normal. All the changes are stored into the stack. 3. Infix to Postfix Conversion: With the help of stacks, you can convert from infix to postfix. 4. Backtracking: You can use stacks to solve various maze puzzling problems. 5. Depth First Search: With the help of stacks, you can perform a searching algorithm named Depth-First Search.
  • 9.
    QUEUES • Queue isknown as a linear data structure. It follows the First-In-First- Out rule. • So, if you push something to the stack then the first value of the stack will pop out. • In the queue, the insertion operation is done from the rear end(back) and the deletion is done from the front.
  • 10.
    IMPLEMENTATION OF QUEUES •Statically: Array implementation of queues allows the static memory allocation of its data elements. It is important to note that in this method, the queue acquires all the features of an array. • Dynamically: Linked list implementation of queues follow the dynamic memory allocation of its data elements. It is important to note that in this method, the queue inherits all the characteristics of a linked list.
  • 11.
    OPERATIONS ON QUEUES •Enqueue - adding an element in the queue if there is space in the queue.
  • 12.
    OPERATIONS ON QUEUES •Dequeue- Removing elements from a queue if there are any elements in the queue
  • 13.
    OPERATIONS ON QUEUES •Front - This function returns the front element of the queue. • Size - This function returns the size of a queue or the number of elements in a queue.
  • 14.
    TYPES OF QUEUES •The standard queue data structure has the following variations: 1. Double-ended queue 2. Circular queue • Double-ended queue: In a standard queue, a character is inserted at the back and deleted in the front. However, in a double-ended queue, characters can be inserted and deleted from both the front and back of the queue.
  • 15.
    TYPES OF QUEUES •Circular queues: A circular queue is an improvement over the standard queue structure. • In a standard queue, when an element is deleted, the vacant space is not reutilized. However, in a circular queue, vacant spaces are reutilized. • While inserting elements, when you reach the end of an array and you need to insert another element, you must insert that element at the beginning.