What is a Stack
- Stack is an abstract data type that serves as a collection of elements, with two main principal operations: Push, which adds an element to the collection, and Pop, which removes the most recently added element ### what is Queues ? A queue is an ordered collection of items where the addition of new items happens at one end, called the “rear,” and the removal of existing items occurs at the other end, commonly called the “front.”
What is a Queue
Common terminology for a queue is 1-Enqueue - Nodes or items that are added to the queue.
2-Dequeue - Nodes or items that are removed from the queue. If called when the queue is empty an exception will be raised.
3-Front - This is the front/first Node of the queue.
4-Rear - This is the rear/last Node of the queue.
5-Peek - When you peek you will view the value of the front Node in the queue. If called when the queue is empty an exception will be raised.
6-IsEmpty - returns true when queue is empty otherwise returns false.
7-Queues follow these concepts: First In First Out
Last In Last Out
What are Queues used for?
Queue, as the name suggests is used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn.
What are Stacks used for?
Stacks are used to implement functions, parsers, expression evaluation, and backtracking algorithms. A pile of books, a stack of dinner plates, a box of pringles potato chips can all be thought of examples of stacks. The basic operating principle is that last item you put in is first item you can take out.
What is the difference between queues and Stacks?
Stacks are based on the LIFO principle, i.e., the element inserted at the last, is the first element to come out of the list.
Queues are based on the FIFO principle, i.e., the element inserted at the first, is the first element to come out of the list. In queues we maintain two pointers to access the list.
