神刀安全网

Difference Between Stack and Queue

In this article you will learn about difference between stack and queue.

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:

int isEmpty() {     if(top==-1)         return 1;     else         return 0; } 

The condition to check if a stack is full:

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:

int isEmpty() {     if(front==-1 || front==rear+1)         return 1;     else         return 0; } 

The condition to check if a queue is full:

int isFull() {     if(rear==MAX-1)         return 1;     else         return 0; } 

Difference Between Stack and Queue

Image Source

Difference Between Stack and Queue

St

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Difference Between Stack and Queue

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址