-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.c
More file actions
67 lines (52 loc) · 670 Bytes
/
Stack.c
File metadata and controls
67 lines (52 loc) · 670 Bytes
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
#include<stdio.h>
#include<stdlib.h>
struct stack
{
int data;
struct stack *next;
};
typedef struct stack stack;
stack *p=NULL;
void push(int data)
{
if(p==NULL)
{
p=(stack*)malloc(sizeof(stack));
p->next=NULL;
}
p->data=data;
stack *temp=(stack*)malloc(sizeof(stack));
temp->next=p;
p=temp;
}
int pop()
{
if(p->next==NULL)
return -1;
int result=p->next->data;
stack *temp=p;
p=p->next;
free(temp);
return result;
}
void show()
{
stack *temp;
temp=p->next;
while(temp!=NULL)
{
printf("%d\n",temp->data);
temp=temp->next;
}
}
int main(){
push(10);
push(20);
push(30);
show();
pop();
pop();
pop();
show();
return 0;
}