Queue Data Structure(QDS)

Definition – QDS is a linear data structure which operates in a FIFO(First In First Out) or vise-versa LILO

Above is an image of QDS in memory.. Now we will discuss some operations…

STANDARD QUEUE OPERATIONS

  • enqueue();
  • dequeue();
  • isFull();
  • isEmpty();
  • count();

These were some operations if your reading this most probably you understand it…Now I will explain code theory…

//Initializations or declarations int arr[4]; int rear = -1; int front = -1; //operations isEmpty() { if(front == -1 && rear == -1) { return true; } else { return false; } } isFull() { if(rear == size(arr) – 1){ return true; } else{ return false; } } enqueue(value) { if(isFull()) { return; } else if(isEmpty()) { rear = 0; front = 0; } else { rear++; } arr[rear] = value; } dequeue() { int x = 0; if(isEmpty()) { return; } else if(front == rear) { x = arr[front] front = -1; rear = -1; } else { x = arr[front] front++; } return x; }

This was the code theory if you understand it it can not only be usedd in c++ but also python,java etc,etc….On my next post I will be giving examples to use in real life

Published by Hriday Barot's Blog

I am Hriday Barot

Leave a comment

Design a site like this with WordPress.com
Get started