-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwentyFirst.cpp
47 lines (47 loc) · 919 Bytes
/
twentyFirst.cpp
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 <iostream>
using namespace std;
struct node {
int data;
node* next;
};
node* top;
node* getNewNode(int x)
{
node* temp = new node();
temp->data = x;
temp->next = NULL;
return temp;
}
void push(int x) {
node* temp = getNewNode(x);
temp->next = top;
top = temp;
}
int pop(/* arguments */) {
node* temp = top;
top = top->next;
return temp->data;
}
void display(/* arguments */) {
node* temp = top;
while (temp != NULL) {
std::cout << temp->data << '\n';
temp = temp->next;
}
}
int main(int argc, char const *argv[]) {
top = NULL;
int n[10];
std::cout << "Enter the values " << '\n';
for (int i = 0; i < 10; i++) {
cin >> n[i];
push(n[i]);
}
display();
std::cout << '\n';
for (int i = 0; i < 10; i++) {
n[i] = pop();
std::cout << n[i] << '\n';
}
return 0;
}