Expt 4 Ds
Expt 4 Ds
#include<stdio.h>
#include<stdlib.h>
struct node
int info;
}*top=NULL;
int pop();
int peek();
int isEmpty();
void display();
main()
int choice,item;
while(1)
printf("\n1.Push\n");
printf("2.Pop\n");
printf("5.Quit\n");
scanf("%d",&choice);
switch(choice)
case 1:
push(item);
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
scanf("%d",&item);
push(item);
break;
case 2:
item=pop();
break;
case 3:
break;
case 4:
display();
break;
case 5:
exit(1);
default:
printf("Wrong choice\n");
printf("Stack Overflow\n");
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
if(tmp==NULL)
printf("Stack Overflow\n");
return;
tmp->info=item;
tmp->link=top;
top=tmp;
int pop()
int item;
if(isEmpty())
printf("Stack Underflow\n");
exit(1);
tmp=top;
item=tmp->info;
top=top->link;
free(tmp);
return item;
int peek()
if(isEmpty())
printf("Stack Underflow\n");
Data Structures & Algorithms , Department of Computer Engineering RollNo. 23CO 76
exit(1);
}
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
printf("Stack Underflow\n");
exit(1);
return top->info;
int isEmpty()
if(top==NULL)
return 1;
else
return 0;
void display()
ptr=top;
if(isEmpty())
printf("Stack is empty\n");
return;
while(ptr!=NULL)
printf("%d\n",ptr->info);
ptr=ptr->link;
printf("\n");
#include<stdio.h>
#include<stdlib.h>
struct node
int info;
}*front=NULL,*rear=NULL;
int del();
int peek();
int isEmpty();
void display();
main()
int choice,item;
while(1)
printf("\n1.Insert\n");
printf("2.Delete\n");
printf("5.Quit\n");
scanf("%d",&choice);
switch(choice)
case 1:
insert(item);
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
scanf("%d",&item);
insert(item);
break;
case 2:
item=del();
break;
case 3:
break;
case 4:
display();
break;
case 5:
exit(1);
default:
printf("Wrong choice\n");
return item;
Data Structures & Algorithms , Department of Computer Engineering RollNo. 23CO 76
}
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
if(tmp==NULL)
return;
tmp->info=item;
tmp->link=NULL;
if(front==NULL)
front=tmp;
else
rear->link=tmp;
rear=tmp;
int del()
int item;
if(isEmpty())
printf("Queue Underflow\n");
exit(1);
tmp=front;
item=tmp->info;
front=front->link;
free(tmp);
return item;
int peek()
if(isEmpty())
Data Structures & Algorithms , Department of Computer Engineering RollNo. 23CO 76
{
printf("Queue Underflow\n");
AGNEL INSTITUTE OF TEC HNOLOGY & DESIGN
if(isEmpty())
printf("Queue Underflow\n");
exit(1);
return front->info;
int isEmpty()
if(front==NULL)
return 1;
else
return 0;
void display()
ptr=front;
if(isEmpty())
printf("Queue is empty\n");
return;
while(ptr!=NULL)
printf("%d ",ptr->info);
ptr=ptr->link;
printf("\n\n");