This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMain.hx
55 lines (42 loc) · 1.74 KB
/
Main.hx
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
package;
import haxe.ds.GenericStack;
class Main {
public static function main () {
//----------------------------------------------------------------------
trace('--- MAKE A NEW STACK OF INTEGERS ---');
var a = new GenericStack<Int>();
//----------------------------------------------------------------------
trace('--- Stack is empty: ' + a.isEmpty() + ' ---');
//----------------------------------------------------------------------
trace('--- ADD ELEMENTS TO STACK ---');
a.add(3);
a.add(2);
a.add(1);
a.add(0);
a.add(11);
a.add(18);
a.add(5);
a.add(6);
trace(a);
//----------------------------------------------------------------------
trace('--- Stack is empty: ' + a.isEmpty() + ' ---');
//----------------------------------------------------------------------
trace('--- Upper element of the stack: ' + a.head.elt + ' ---');
trace('--- Next element of the stack: ' + a.head.next.elt + ' ---');
trace('--- And next element of the stack: ' + a.head.next.next.elt + ' ---');
//----------------------------------------------------------------------
trace('--- REMOVE ELEMENTS 1, 8 AND 5 FROM THE STACK ---');
trace(a.remove(1));
trace(a.remove(8));
trace(a.remove(5));
trace(a);
//----------------------------------------------------------------------
trace('--- GET 3 UPPERS ELEMENTS AND REMOVE IT ---');
trace(a.pop()); // get first upper element of the stack and remove it
trace(a.pop()); // get second upper element of the stack and remove it
trace(a.pop()); // and get third upper element of the stack and remove it
trace(a);
//----------------------------------------------------------------------
trace('--- STACK TO STRING: ' + a.toString() + ' ---');
}
}