-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathBreadth first search.html
95 lines (45 loc) · 1.03 KB
/
Breadth first search.html
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<html>
<head>
<style>
body { background-color: white;
}
h1 {
color: #6f69ac;
text-align: center;
line-height: 0.3;
}
h5 {
color: #fd6f96;
text-align: center;
}
p {
color: #716bad;
font-family: Arial;
}
ol {
margin-left: 20px;
}
li {
color: #716bad;
font-family: Monospace;
}
</style>
</head>
<body>
<h1>Inorder Tree Traversal without Recursion</h1>
<h5>By: Sruthi s </h5>
<p>Below is an algorithm for traversing binary tree using stack</p>
<ol>
<li>Create an empty stack S.</li>
<li>Initialize current node as root</li>
<li>Push the current node to S and set current = current->left until current is NULL</li>
<li>If current is NULL and stack is not empty then
<ol type="a">
<li> Pop the top item from stack.</li>
<li> Print the popped item, set current = popped_item->right </li>
<li> Go to step 3.</li>
</ol>
<li> If current is NULL and stack is empty then we are done.</li>
</ol>
</body>
</html>