top of page

Queue Using Single Pointer Array

Writer's picture: Code CrazeCode Craze

Updated: Mar 28, 2023



#include <stdio.h>

#include<stdlib.h>

#include<math.h>


#define size 100

int queue[size];

int top=-1;


void enque(void);

void deque(void);

void peek(void);

void isEmpty(void);

void isFull(void);

void display(void);


void main() {

int c,e;

do{

switch(c)

{

case 1:

enque();

break;

case 2:

deque();

break;

case 3:

peek();

break;

case 4:

isEmpty();

break;

case 5:

isFull();

break;

case 6:

display();

break;

case 7:

printf("\n\n----Exit from program successfully----");

printf("\n--------------Thank you--------------");

exit(0);

}

printf("\n1 : Enque\n2 : Deque\n3 : Peek\n4 : isEmpty\n5 : isFull\n6 : Display");

printf("\nEnter your choice : ");

scanf("%d",&c);

}while(c);

}


void enque()

{

int v;

printf("\nEnter value : ");

scanf("%d",&v);

if(top==size-1)

{

printf("\nQueue is full!!");

}

else

{

top++;

queue[top]=v;

}

}


void display()

{

int i;

if(top==-1)

{

printf("\nQueue is empty");

}

else

{

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

{

printf("--%d",queue[i]);

}

}

}


void deque()

{

if(top==-1)

{

printf("\nQueue is empty!!");

}

else

{

int i;

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

{

queue[i]=queue[i+1];

}

top--;

}

}


void peek()

{

printf("\nTop : %d",top);

printf("\nTop Value: %d",queue[top]);

}


void isEmpty()

{

if(top==-1)

{

printf("\nQueue is empty!!");

}

else

{

printf("\nQueue is not empty!!");

}

}


void isFull()

{

if(top==size-1)

{

printf("\nQueue is full!!");

}

else

{

printf("\nQueue is not full!!");

}

}

2 views0 comments

Recent Posts

See All

Stack Using Queue

A stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...

Comments


bottom of page