Stack
A Stack data structure works on Last In First Out principle, also abbreviated as LIFO. A Stack requires only one reference variable, known as a top pointer. Stack data structures are normally represented as a vertical representation of data items.
A Stack Data Structure can be represented in static arrays as well as linked lists. In a stack, the data items can be inserted and deleted from the same end. The element to be inserted first is the last element to get deleted. Both the operations, insertion and deletion occur at the TOP reference pointer. A Stack doesn’t necessarily contain ordered collection of data items.
Stack Implementations:
Stack data structure is used in infix to postfix conversion, scheduling algorithms, evaluation of an expression and depth first search.
The condition to check if a stack is empty:
1 2 3 4 5 6 7 8 9 |
int isEmpty() { if(top==-1) return 1; else return 0; } |
The condition to check if a stack is full:
1 2 3 4 5 6 7 8 9 |
int isFull() { if(top==MAX-1) return 1; else return 0; } |
Queue
A Queue data structure works on First In First Out principle, also abbreviated as FIFO. A Queue requires two reference variables. Queue is normally represented as a horizontal representation of data items. The Queue data structure contains FRONT and REAR as its reference points for data processing.
A Queue can also be represented in by static arrays as well as linked lists. In a Queue, the data items can be inserted and deleted from different ends. The element to be inserted first is the first element to get deleted. The insertion operation is done at rear end whereas the deletion occurs at the front end. A Queue contains ordered collection of data items. A Queue can be divided into sub sections and it has the following extensions: Double Ended Queue, Simple Queue, Priority Queue and Circle Queue.
Queue Implementations:
A Queue offers services in operations research, transportation and computer science that involves persons, data, events and objects to be stored for later processing.
The condition to check if a queue is empty:
1 2 3 4 5 6 7 8 9 |
int isEmpty() { if(front==-1 || front==rear+1) return 1; else return 0; } |
The condition to check if a queue is full:
1 2 3 4 5 6 7 8 9 |
int isFull() { if(rear==MAX-1) return 1; else return 0; } |
Add comment