123 Eng

Engineering the engineers™


Latest Jobs   Forum Map

 


Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

   Computer Science / IT
   Electronics
   Electrical
   Mechanical
   Chemical
   Civil

   CAT / MBA

   GMAT / Foreign MBA
Latest Jobs

Engineering Jobs / Technical Jobs
Management Jobs

Sitemap
Terms of use

Displaying  Source Code(s)  
 

 
Implentation of queue using arrays - QUEUE.C

--------------------------------------------------------------------------------

Description : Implentation of queue using arrays

Code :
/* Implentation of queue using arrays - QUEUE.C */
# include <stdio.h>
# include <conio.h>
# define SIZE 10
int arr[SIZE], front = -1, rear = -1, i ;
void enqueue() ;
void dequeue() ;
void display() ;
void main()
{
int ch ;
clrscr() ;
do
{
printf("
[1].ENQUEUE [2].DEQUEUE [3].Display [4].Exit<BR>) ;
printf("
Enter your choice [1-4] : ") ;
scanf("%d", &ch) ;
switch(ch)
{
case 1 :
enqueue() ;
break ;
case 2 :
dequeue() ;
break ;
case 3 :
display() ;
break ;
case 4 :
break ;
default :
printf("
Invalid option<BR>) ;
getch() ;
}
} while(ch != 4) ;
getch() ;
}

void enqueue()
{
if(rear == SIZE - 1)
{
printf("
Queue is full (overflow)<BR>) ;
getch() ;
return ;
}
rear++ ;
printf("
Enter the element to ENQUEUE : ") ;
scanf("%d", &arr[rear]) ;
if(front == -1)
front++ ;
}

void dequeue()
{
if(front == -1)
{
printf("
Queue is empty (underflow)<BR>) ;
getch() ;
return ;
}
printf("
The DEQUEUE element is : %d<BR>, arr[front]) ;
getch() ;
if(front == rear)
front = rear = -1 ;
else
front++ ;
}

void display()
{
if(front == -1)
{
printf("
Queue is empty (underflow)<BR>) ;
getch() ;
return ;
}
printf("
The elements in queue are :

FRONT ->") ;
for(i = front ; i <= rear ; i++)
printf(" ... %d", arr[i]) ;
printf(" ... <- REAR<BR>) ;
getch() ;
}


 

 

 

Contribute content or training reports / feedback / Comments
job placement papers
All rights reserved copyright 123ENG