0% found this document useful (0 votes)
31 views

Automata Data Structure OS Graph Theory Microprocessor: Tutorials

This document discusses circular queues, which are a type of queue data structure that has a fixed size and allows addition of data at the rear end and removal of data from the front end in a circular manner. It provides an algorithm for insertion in a circular queue and includes C code implementation of insertion in a circular queue as an example.

Uploaded by

Sanskruti Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Automata Data Structure OS Graph Theory Microprocessor: Tutorials

This document discusses circular queues, which are a type of queue data structure that has a fixed size and allows addition of data at the rear end and removal of data from the front end in a circular manner. It provides an algorithm for insertion in a circular queue and includes C code implementation of insertion in a circular queue as an example.

Uploaded by

Sanskruti Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

9/15/2017 Circular Queues

Toggle navigation Scanftree.com

Academic Tutorials

Automata
Data Structure
OS
Graph Theory
Microprocessor

Cryptography
Compiler Design
Computer Graphics
IPv4
Parallel Algorithm

Database Concept
DBMS
SQL
SQLite
Programming

Tutorials
C
C++
JAVA
C#
Python

Programs
C
C++
JAVA
Python

Preparation

Syllabus
Gate

Interview
Technical
HR/PI

Gk/Aptitude

http://scanftree.com/Data_Structure/circular-queue 1/12
9/15/2017 Circular Queues

Gk
Aptitude

MCQ
C
JAVA
Networking

Miscellaneous

Calculator
Health
Math

Developers
Css/Html Maker
Cheat Sheets
SEO Tools

Other
Math Formulas
IFSC Codes

Search

Data Structure

Introduction

Linked List

Singly Linked List


Circular Queue
Doubly Linked List
A circular queue is an abstract data type that contains a collection of data which

Circular Linked List allows addition of data at the end of the queue and removal of data at the beginning
of the queue. Circular queues have a fixed size.
Stack Circular queue follows FIFO principle. Queue items are added at the rear end and the
items are deleted at front end of the circular queue.
Queues

Queues

Static Queues

Dynamic Queues

» Circular Queues

http://scanftree.com/Data_Structure/circular-queue 2/12
9/15/2017 Circular Queues

Double-ended

Queue

Recursion

Searching

Sorting Algorithms

Algorithms

Tree
Algorithm for Insertion in a circular queue

Interview Question
Insert CircularQueue ( )

1. If (FRONT == 1 and REAR == N) or (FRONT == REAR + 1) Then

2. Print: Overflow

3. Else

4. If (REAR == 0) Then [Check if QUEUE is empty]

(a) Set FRONT = 1

(b) Set REAR = 1

5. Else If (REAR == N) Then [If REAR reaches end if QUEUE]

6. Set REAR = 1

7. Else

8. Set REAR = REAR + 1 [Increment REAR by 1]

[End of Step 4 If]

9. Set QUEUE[REAR] = ITEM

10. Print: ITEM inserted

[End of Step 1 If]

http://scanftree.com/Data_Structure/circular-queue 3/12
9/15/2017 Circular Queues

11. Exit

Implementation of insertion in circular queue

#include<stdio.h>

#include<string.h>

#include<conio.h>

#include<ctype.h>

#include<stdlib.h>

#define size 8

int rear, front;

int no;

int q[size];

int rear=-1;

int front=-1;

/* Function to create queue */

void Insert_queue()

char ans;

http://scanftree.com/Data_Structure/circular-queue 4/12
9/15/2017 Circular Queues

printf("\n Enter 'n' for break:-");

ans=getch();

while(ans!='n')

printf("\n Input the Element : ");

scanf("%d",&no);

if((front==0) && (rear==size-1))

printf("\n Queue is Overflow");

return;

else if(rear==front-1)

printf("\n Queue is overflow");

return;

else if(front < 0) /* Insert First Element */

http://scanftree.com/Data_Structure/circular-queue 5/12
9/15/2017 Circular Queues

front=0;

rear=0;

q[rear]=no;

else if(rear==size-1)

rear=0;

q[rear]=no;

else

rear++;

if(rear==front)

printf("\n Queue is overflow ");

return;

else

q[rear]=no;

http://scanftree.com/Data_Structure/circular-queue 6/12
9/15/2017 Circular Queues

printf("\n Enter 'n' for break:-");

ans = getch();

void Display_queue()

int i;

if(front < 0)

printf("\n Queue is underflow");

return;

printf("\nItems are:\n");

if(rear>=front)

for(i=front; i<=rear; i++)

printf("\n q[%d] = %d",i,q[i]);

http://scanftree.com/Data_Structure/circular-queue 7/12
9/15/2017 Circular Queues

else

for(i=front;i < size; i++)

printf("\n l-2 q[%d] = %d",i,q[i]);

for(i=0;i<=rear;i++)

printf("\n l-3 q[%d] = %d",i,q[i]);

/* Function main */

void main()

clrscr();

Insert_queue();

Display_queue();

getch();

http://scanftree.com/Data_Structure/circular-queue 8/12
9/15/2017 Circular Queues

Algorithm for Deletion in a circular queue

Delete CircularQueue ( )

1. If (FRONT == 0) Then [Check for Underflow]

2. Print: Underflow

3. Else

4. ITEM = QUEUE[FRONT]

5. If (FRONT == REAR) Then [If only element is left]

(a) Set FRONT = 0

(b) Set REAR = 0

6. Else If (FRONT == N) Then [If FRONT reaches end if QUEUE]

7. Set FRONT = 1

http://scanftree.com/Data_Structure/circular-queue 9/12
9/15/2017 Circular Queues

8. Else

9. Set FRONT = FRONT + 1 [Increment FRONT by 1]

[End of Step 5 If]

10. Print: ITEM deleted

[End of Step 1 If]

11. Exit

C fuction of deletion in circular queue

void Delete_queue()

if(front < 0)

printf("\n Queue is Underflow");

return;

no=q[front];

q[front]=NULL;

printf("\n Element deleted : ",no);

if(front==rear)

http://scanftree.com/Data_Structure/circular-queue 10/12
9/15/2017 Circular Queues

front=-1;

rear=-1;

else if(front==size-1)

front=0;

else

front++;

Next →

Quantitative Aptitude

Arithmetic DI

Reasoning

Logical Verbal
Nonverbal

Programming

C C++ C# Java CSE

http://scanftree.com/Data_Structure/circular-queue 11/12
9/15/2017 Circular Queues

Interview

HR Technical Interview

http://scanftree.com/Data_Structure/circular-queue 12/12

You might also like