-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstacklink.c
47 lines (47 loc) · 844 Bytes
/
stacklink.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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node *next;
};
struct node*top=NULL;
void push(int data){
struct node *new=(struct node*)malloc(sizeof(struct node));
if (new==NULL){
printf("memory insufficient");
}
new->data=data;
new->next=NULL;
struct node *ptr=top;
if(ptr==NULL){
top=new;
}
else{
new->next=top;
top=new;
}
}
void pop(){
struct node*ptr=top;
printf("popped item is %d\n",ptr->data);
ptr=ptr->next;
top=ptr;
}
void display(){
struct node *ptr=top;
while(ptr!=NULL){
printf("%d",ptr->data);
ptr=ptr->next;
}
}
void main(){
int data;
scanf("%d",&data);
push(data);
scanf("%d",&data);
push(data);
scanf("%d",&data);
push(data);
pop();
display();
}