-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_llist.c
71 lines (71 loc) · 1.06 KB
/
stack_llist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
struct node{
int data;
struct node *ptr;
};
struct node *top=NULL;
struct node *insert()
{
struct node *new_node;
int num;
printf("Enter -1 to stop.");
printf("\nPush elements in stack: ");
scanf("%d",&num);
while(num!=-1)
{
new_node=(struct node *)malloc(sizeof(struct node));
new_node->data=num;
if(top==NULL)
{
top=new_node;
new_node->ptr=NULL;
}
else
{
new_node->ptr=top;
top=new_node;
}
scanf("%d",&num);
}
return top;
}
struct node *display()
{
struct node *z;
z=top;
while(z!=NULL)
{
printf("\t%d",z->data);
z=z->ptr;
}
return top;
}
struct node *enter()
{
struct node *new_node;
int num;
printf("\nEnter element to push: ");
scanf("%d",&num);
new_node->ptr=top;
top=new_node;
return top;
}
struct node *del()
{
struct node *z;
z=top;
top=top->ptr;
free(z);
printf("\nAfter poping topmost element: ");
return top;
}
int main()
{
insert();
display();
del();
display();
return 0;
}