You are on page 1of 2

QUEUE IMPLEMENTATION USING ARRAYS

#inc lude<std io .h>


#inc lude<con io .h>
#def ine qmax 5
i n t f ron t=- 1 , rea r=-1 ,q [qmax] ;
vo id i n se r t i on ( in t i t em)
{
i f ( rea r==qmax- 1)
pr in t f ( " \nThe queue i s f u l l \ n " ) ;
e l se
{
i f ( f ron t==-1)
f ron t=0 ;
rea r++;
q[ rea r ]= i tem;
pr in t f ( "Rear=%d" , rea r ) ;
}
}
vo id de le t i on ( )
{
i f ( f ron t==-1)
pr in t f ( " \nThe queue i s empty \n" ) ;
e l se
{
pr in t f ( " \nThe i t em i s de le ted i s %d\n" ,q [ f ron t ] ) ;
i f ( f ron t==rear )
{
f ron t=- 1 , rea r=-1 ;
}
e l se
f ron t++;
}
}
vo id pr in t ( )
{
int i ;
i f ( f ron t==rear+1 | | f ron t==-1)
pr in t f ( " \nThe queue i s empty \n" ) ;
e l se
{
1 | Page aqueue coding
pr in t f ( " F ron t=%d & Rear=%d\n" , f ron t , rea r ) ;
pr in t f ( "The cu r ren t s ta te o f queue i s : " ) ;
f o r ( i= f ron t ; i<=rear ; i++)
pr in t f ( "%d\ t " ,q [ i ] ) ;
pr in t f ( " \n " ) ;
}
}
vo id main ( )
{
i n t ch , i t em;
c l r sc r ( ) ;
pr in t f ( " \n You have the f o l l ow ing cho i ce : " ) ;
pr in t f ( " \n1 . Inse r t \n2 .De le te \n3 .P r in t \n4 .Ex i t " ) ;
do
{
pr in t f ( " \nEn te r the cho i ce : \ t " ) ;
scan f ( "%d" ,&ch ) ;
sw i t ch (ch )
{
case 1 :
pr in t f ( " \nEn te r the e lement to be i n se r ted : \ t " ) ;
scan f ( "%d" ,& i tem) ;
i n se r t i on ( i tem) ;
break ;
case 2 :
de le t i on ( ) ;
break ;
case 3 :
pr in t ( ) ;
break ;
}
}
whi le ( ch !=4) ;
getch ( ) ;
}

2 | Page aqueue coding

You might also like