-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththirtySeven.cpp
54 lines (54 loc) · 1.12 KB
/
thirtySeven.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
48
49
50
51
52
53
54
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
struct node {
int data;
node* right;
node* left;
};
node* getNewNode(int x) {
node* temp = new node();
temp->data = x;
temp->right = NULL;
temp->left = NULL;
return temp;
}
queue<node*> Q;
stack<node*> ST;
node* root = getNewNode(10);
int size = 0;
void create() {
root->right = getNewNode(30);
root->left = getNewNode(20);
root->right->right = getNewNode(70);
root->right->left = getNewNode(60);
root->left->left = getNewNode(40);
root->left->right = getNewNode(50);
}
void reverselevelOrder() {
node* temp;
node* temp1;
Q.push(root);
while (!Q.empty()) {
temp = Q.front();
Q.pop();
if (temp->right != NULL) {
Q.push(temp->right);
}
if (temp->left != NULL) {
Q.push(temp->left);
}
ST.push(temp);
}
while (!ST.empty()) {
temp1 = ST.top();
ST.pop();
std::cout << temp1->data << ' ';
}
}
int main(int argc, char const *argv[]) {
create();
reverselevelOrder();
return 0;
}