- Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathstack_using_ll.cpp
More file actions
Latest commit
50 lines (49 loc) · 658 Bytes
/
Copy pathstack_using_ll.cpp
File metadata and controls
50 lines (49 loc) · 658 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
#include<iostream>
usingnamespacestd;
structnode
{
int data;
node* next;
};
node* head;
voidpush(int x)
{
node* temp=newnode();
temp->data=x;
temp->next=NULL;
if(head==NULL){
head=temp;
return;
}
temp->next=head;
head=temp;
}
voidtop()
{
node* temp=head;
cout<<"Top elements is: "<<temp->data<<endl;
}
voidprint(node* p)
{
if(p==NULL) return;
cout<<p->data<<"";
print(p->next);
}
intmain()
{
head=NULL;
int n,x;
cout<<"How many numbers:";
cin>>n;
for (int i = 0; i < n; ++i)
{
cout<<"Enter numbers you want to push into stack: ";
cin>>x;
push(x);
}
print(head);
cout<<""<<endl;
top();
cout<<""<<endl;
return0;
}