#include<stdio.h>
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *top;
int main()
{
struct node *ptr,*cpt;
int n;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the element to insert");
scanf("%d",&ptr->info);
top=ptr;
do
{
printf("\nPress 1 for push");
printf("\nPress 2 for pop");
printf("\nPress 3 for display");
printf("\nPress 4 for exit");
scanf("%d",&n);
//Push operation
switch(n)
{
case 1: cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the element to insert");
scanf("%d",&cpt->info);
cpt->link=top;
top=cpt;
break;
case 2: cpt=top;
top=cpt->link;
free(cpt);
break;
case 3: cpt=top;
while(cpt!=NULL)
{
printf("%d\t",cpt->info);
cpt=cpt->link;
}
}
}
while(n<4);
return 0;
}
#include<stdlib.h>
struct node
{
int info;
struct node *link;
};
struct node *top;
int main()
{
struct node *ptr,*cpt;
int n;
ptr=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the element to insert");
scanf("%d",&ptr->info);
top=ptr;
do
{
printf("\nPress 1 for push");
printf("\nPress 2 for pop");
printf("\nPress 3 for display");
printf("\nPress 4 for exit");
scanf("%d",&n);
//Push operation
switch(n)
{
case 1: cpt=(struct node *)malloc(sizeof(struct node));
printf("\nEnter the element to insert");
scanf("%d",&cpt->info);
cpt->link=top;
top=cpt;
break;
case 2: cpt=top;
top=cpt->link;
free(cpt);
break;
case 3: cpt=top;
while(cpt!=NULL)
{
printf("%d\t",cpt->info);
cpt=cpt->link;
}
}
}
while(n<4);
return 0;
}
No comments:
Post a Comment