forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbs_stack_test.js
123 lines (109 loc) · 3.17 KB
/
bs_stack_test.js
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
var Caml_option = require("../../lib/js/caml_option.js");
var Js_undefined = require("../../lib/js/js_undefined.js");
var Belt_MutableQueue = require("../../lib/js/belt_MutableQueue.js");
var Belt_MutableStack = require("../../lib/js/belt_MutableStack.js");
function inOrder(v) {
var current = v;
var s = {
root: null
};
var q = Belt_MutableQueue.make(/* () */0);
while(current !== undefined) {
var v$1 = current;
Belt_MutableStack.push(s, v$1);
current = v$1.left;
};
while(s.root !== null) {
current = Belt_MutableStack.popUndefined(s);
var v$2 = current;
Belt_MutableQueue.add(q, v$2.value);
current = v$2.right;
while(current !== undefined) {
var v$3 = current;
Belt_MutableStack.push(s, v$3);
current = v$3.left;
};
};
return Belt_MutableQueue.toArray(q);
}
function inOrder3(v) {
var current = v;
var s = {
root: null
};
var q = Belt_MutableQueue.make(/* () */0);
while(current !== undefined) {
var v$1 = current;
Belt_MutableStack.push(s, v$1);
current = v$1.left;
};
Belt_MutableStack.dynamicPopIter(s, (function (popped) {
Belt_MutableQueue.add(q, popped.value);
var current = popped.right;
while(current !== undefined) {
var v = current;
Belt_MutableStack.push(s, v);
current = v.left;
};
return /* () */0;
}));
return Belt_MutableQueue.toArray(q);
}
function inOrder2(v) {
var todo = true;
var cursor = v;
var s = {
root: null
};
var q = Belt_MutableQueue.make(/* () */0);
while(todo) {
if (cursor !== undefined) {
var v$1 = cursor;
Belt_MutableStack.push(s, v$1);
cursor = v$1.left;
} else if (s.root !== null) {
cursor = Belt_MutableStack.popUndefined(s);
var current = cursor;
Belt_MutableQueue.add(q, current.value);
cursor = current.right;
} else {
todo = false;
}
};
return /* () */0;
}
function n(l, r, a) {
return {
value: a,
left: Js_undefined.fromOption(l),
right: Js_undefined.fromOption(r)
};
}
var test1 = n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), Caml_option.some(n(undefined, undefined, 5)), 2)), Caml_option.some(n(undefined, undefined, 3)), 1);
function pushAllLeft(st1, s1) {
var current = st1;
while(current !== undefined) {
var v = current;
Belt_MutableStack.push(s1, v);
current = v.left;
};
return /* () */0;
}
var test2 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), undefined, 1)), undefined, 3);
var test3 = n(Caml_option.some(n(Caml_option.some(n(Caml_option.some(n(undefined, undefined, 4)), undefined, 2)), undefined, 5)), Caml_option.some(n(undefined, undefined, 3)), 1);
console.log(inOrder(test1));
console.log(inOrder3(test1));
var S = 0;
var Q = 0;
exports.S = S;
exports.Q = Q;
exports.inOrder = inOrder;
exports.inOrder3 = inOrder3;
exports.inOrder2 = inOrder2;
exports.n = n;
exports.test1 = test1;
exports.pushAllLeft = pushAllLeft;
exports.test2 = test2;
exports.test3 = test3;
/* test1 Not a pure module */