Professional Documents
Culture Documents
Dsu Uef
Dsu Uef
h>
#define MAX_SIZE 5
#include<stdlib.h>
else if(front==-1)
{
front=rear=0;
}
else if (rear==MAX_SIZE-1 && front !=0)
{
rear=0;
}
else
{
rear++;
queue[rear]=value;
printf("%d enqueued to queue",value );
}
}
int dequeue()
{
int value ;
if(front==-1)
{
printf("\n Queue is empty \n ");
return -1;
}
value=queue[front];
if (front==rear)
front=rear-1;
else if(front==MAX_SIZE-1)
{
front=0;
}
else
{
front++;
}
return value;
}
void display()
{
int i;
if(front==-1)
{
printf("Queue is empty");
return;
}
switch(ch)
{
case 1:
printf("\n Enter the elemnets");
scanf("%d",&value);
enqueue(value);
break;
case 2:
value=dequeue();
if(value==-1)
{
printf("dequeued element %d",value);
}
break;
case 3:
display();
break;
case 4:
printf("exiting from the program");
return 0;
}
}
}
***********************************************************************************
***********************************************
}
else
{
top++;
stack[top]=value;
printf("%d is pushed to the stack",value);
}
}
void pop()
{
if(top==-1)
{
printf("stack is empty");
}
else
{
printf("%d is popped from the stack",stack[top--]);
}
}
void display()
{
int i;
if(top==-1)
{
printf("Stack is empty");
}
else
{
for(i=0;i<top;i++)
{
printf("%d",stack[i]);
}
}
}
int main()
{
int value;
int ch;
while(1)
{
printf("\n ********stack operations**********\n");
printf("\n Menu \n 1.Push 2.Pop 3.Display 4.Exit");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("enter the value");
scanf("%d",&value);
push(value);
break;
case 2:
pop();
break;
case 3:display();
break;
case 4:printf("Exiting from the the loop");
return 0;
default : exit(0);
}
}
}