-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMorris.cpp
More file actions
29 lines (28 loc) · 744 Bytes
/
Morris.cpp
File metadata and controls
29 lines (28 loc) · 744 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
#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
vector<int> inOrder(Node* root)
{
Node*cur=root;
vector<int>v;
//code here
while(cur){
if(!cur->left) {v.push_back(cur->data); cur=cur->right;}
else{
Node*pred=cur->left;
while(pred->right and pred->right!=cur) pred=pred->right;
if(!pred->right){
pred->right=cur;
cur=cur->left;
}
else{
pred->right=NULL;
v.push_back(cur->data);
cur=cur->right;
}
}
}
return v;
}
};