-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
67 lines (37 loc) · 1.72 KB
/
Main.java
File metadata and controls
67 lines (37 loc) · 1.72 KB
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
public class Main {
public static void main(String[] args) {
ConsCell a = null;
ConsCell b = ConsCell.cons(2,a);
ConsCell c = ConsCell.cons(1,b);
int x = ConsCell.length(a) + ConsCell.length(b)+ConsCell.length(c);
System.out.println("Length of list: " + x); // Output: 3
IntList myList = new IntList(null);
myList = myList.cons(10);
myList = myList.cons(20);
ConsCell start = myList.getStart();
while (start != null) {
System.out.println(start.getHead());
start = start.getTail();
}
System.out.println("Length of the list: " + myList.length());
/**
*
SAMPLE MAIN:
// Create instances of ConsCell
ConsCell cell1 = new ConsCell(10, null);
ConsCell cell2 = new ConsCell(20, null);
ConsCell cell3 = new ConsCell(30, null);
// Link the cells together to form a list
cell1.setTail(cell2);
cell2.setTail(cell3);
// Accessing values
System.out.println("Head of cell1: " + cell1.getHead()); // Output: 10
System.out.println("Tail of cell1: " + cell1.getTail().getHead()); // Output: 20
System.out.println("Length of list: " + ConsCell.length(cell1)); // Output: 3
// Cons a new cell onto the list
ConsCell newCell = ConsCell.cons(5, cell1);
System.out.println("New head after cons: " + newCell.getHead()); // Output: 5
System.out.println("Length after cons: " + ConsCell.length(newCell)); // Output: 4
*/
}
}