-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
57 lines (53 loc) · 879 Bytes
/
stack.cpp
File metadata and controls
57 lines (53 loc) · 879 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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream>
struct Node{
int data;
Node* next;
};
void push(Node** head,int val){
Node* q=(Node*)malloc(sizeof(Node*));
q->data=val;
q->next=*head;
*head=q;
}
void disp(Node* h){
while(h!=NULL){
printf("\n%d",h->data);
h=h->next;
}
}
int count(Node* np){
int c=0;
while(np!=NULL){
c++;
np=np->next;
}
return c;
}
int pop(Node** hd){
int ext=(*hd)->data;
(*hd)=(*hd)->next;
return ext;
}
int main(){
Node* head=NULL;
push(&head,3);
push(&head,4);
push(&head,56);
push(&head,34);
push(&head,89);
puts("Before pop");
puts("List is:");
disp(head);
printf("\nTotal items:%d",count(head));
printf("pop item is %d",pop(&head));
printf("pop item is %d",pop(&head));
puts("After pop");
puts("List is:");
disp(head);
printf("\nTotal items:%d",count(head));
getchar();
return 0;
}