1/PROGRAM:StacksInsertAndDeleteEnd/
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node *rlink;
struct node *llink;
};
typedef struct node* NODE;
NODE push(NODE);
NODE pop(NODE);
void display(NODE);
NODE createNode();
int main(){
int ch;
NODE head=NULL;
for(;;){
printf("\n\n---------PRESS-----------\n1:To push at end\n2:To pop at end\n3:To display\n4:To
exit>\n");
scanf("%d",&ch);
switch(ch)
{
case 1:head=push(head);
break;
case 2:head=pop(head);
break;
case 3:display(head);
break;
case 4:printf("BYE BYE");
exit(0);
break;
default:printf("\nInvalid choice,please try again");
return 0;
NODE push(NODE h)
NODE New;
if(h == NULL)
New = createNode();
printf("\nThe stack is empty new node is the first node");
h=New;
else
New=createNode();
NODE temp;
for(temp=h; temp->rlink!=NULL; temp=temp->rlink);
New->llink=temp;
temp->rlink=New;
return h;
NODE pop(NODE h)
if(h == NULL)
printf("\nThe stack is empty. Hence cannot be poped");
return NULL;
else if(h->rlink==NULL)
free(h);
return NULL;
else
{
NODE temp=h;
while(temp->rlink!=NULL)
temp=temp->rlink;
temp->llink->rlink = NULL;
free(temp);
return h;
void display(NODE h)
NODE temp=h;
if(h==NULL)
printf("\nThe stack is empty");
else
printf("\nThe elements of the stack are>");
while(temp!=NULL)
printf("\n%d",temp->data);
temp=temp->rlink;
}
}
NODE createNode()
NODE New;
New=(NODE)malloc(sizeof(struct node));
New->rlink=NULL;
New->llink=NULL;
printf("\nEnter the data>");
scanf("%d:",&New->data);
return New;
}
2/PROGRAM:QueuesInsertFrontDeleteEnd/
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node *rlink;
struct node *llink;
};
typedef struct node* NODE;
void enqueue();
void dequeue();
void display();
NODE createNode();
NODE head=NULL;
NODE end=NULL;
int main(){
int ch;
for(;;){
printf("\n\n---------PRESS-----------\n1:To enqueue at front\n2:To dequeue at end\n3:To display\
n4:To exit>\n");
scanf("%d",&ch);
switch(ch)
case 1:enqueue();
break;
case 2:dequeue();
break;
case 3:display();
break;
case 4:printf("BYE BYE");
exit(0);
break;
default:printf("\nInvalid choice,please try again");
return 0;
void enqueue()
NODE New;
if(end==NULL && head==NULL)
New = createNode();
printf("\nThe queue is empty new node is the first node");
end=New;
head=New;
else
New=createNode();
New->rlink=head;
head->llink=New;
head=New;
void dequeue()
if(end==NULL && head==NULL)
printf("\nThe queue is empty. Hence cannot be dequeued");
else if(head->rlink==NULL && end->rlink==NULL)
head=NULL;
end=NULL;
else
NODE temp=end;
end=temp->llink;
end->rlink=NULL;
free(temp);
}
}
void display()
NODE temp=head;
if(head==NULL)
printf("\nThe queue is empty");
else
printf("\nThe elements of the queue are>");
while(temp!=NULL)
printf("\t%d",temp->data);
temp=temp->rlink;
NODE createNode()
NODE New;
New=(NODE)malloc(sizeof(struct node));
New->rlink=NULL;
New->llink=NULL;
printf("\nEnter the data>");
scanf("%d:",&New->data);
return New;
}
3/PROGRAM:QueuesInsertEndDeleteFront/
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node *rlink;
struct node *llink;
};
typedef struct node* NODE;
void enqueue();
void dequeue();
void display();
NODE createNode();
NODE head=NULL;
NODE end=NULL;
int main(){
int ch;
for(;;){
printf("\n\n---------PRESS-----------\n1:To enqueue at end\n2:To dequeue at front\n3:To display\
n4:To exit>\n");
scanf("%d",&ch);
switch(ch)
case 1:enqueue();
break;
case 2:dequeue();
break;
case 3:display();
break;
case 4:printf("BYE BYE");
exit(0);
break;
default:printf("\nInvalid choice,please try again");
return 0;
void enqueue()
NODE New;
if(end==NULL && head==NULL)
New = createNode();
printf("\nThe queue is empty new node is the first node");
end=New;
head=New;
else
New=createNode();
New->llink=end;
end->rlink=New;
end=New;
void dequeue()
if(head == NULL)
printf("\nThe queue is empty. Hence cannot be dequeued");
else if(head->rlink==NULL)
free(head);
else
NODE temp=head;
head=temp->rlink;
head->llink=NULL;
free(temp);
void display()
NODE temp=head;
if(head==NULL)
printf("\nThe queue is empty");
else
printf("\nThe elements of the queue are>");
while(temp!=NULL)
printf("\t%d",temp->data);
temp=temp->rlink;
NODE createNode()
NODE New;
New=(NODE)malloc(sizeof(struct node));
New->rlink=NULL;
New->llink=NULL;
printf("\nEnter the data>");
scanf("%d:",&New->data);
return New;
}
4/PROGRAM:StacksInsertAndDeleteFront/
#include<stdio.h>
#include<stdlib.h>
struct node
int data;
struct node *rlink;
struct node *llink;
};
typedef struct node* NODE;
NODE push(NODE);
NODE pop(NODE);
void display(NODE);
NODE createNode();
int main(){
int ch;
NODE head=NULL;
for(;;){
printf("\n\n---------PRESS-----------\n1:To push at front\n2:To pop at front\n3:To display\n4:To
exit>\n");
scanf("%d",&ch);
switch(ch)
{
case 1:head=push(head);
break;
case 2:head=pop(head);
break;
case 3:display(head);
break;
case 4:printf("BYE BYE");
exit(0);
break;
default:printf("\nInvalid choice,please try again");
return 0;
NODE push(NODE h)
NODE New;
if(h == NULL)
New = createNode();
printf("\nThe stack is empty new node is the first node");
h=New;
}
else
New=createNode();
New->rlink=h;
h->llink=New;
h=New;
return h;
NODE pop(NODE h)
if(h == NULL)
printf("\nThe stack is empty. Hence cannot be poped");
return NULL;
else if(h->rlink==NULL)
free(h);
return NULL;
else
NODE temp=h;
h=temp->rlink;
h->llink=NULL;
free(temp);
return h;
void display(NODE h)
NODE temp=h;
if(h==NULL)
printf("\nThe stack is empty");
else
printf("\nThe elements of the stack are>");
while(temp!=NULL)
printf("\n%d",temp->data);
temp=temp->rlink;
NODE createNode()
NODE New;
New=(NODE)malloc(sizeof(struct node));
New->rlink=NULL;
New->llink=NULL;
printf("\nEnter the data>");
scanf("%d:",&New->data);
return New;