-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListListDemo.java
More file actions
43 lines (35 loc) · 908 Bytes
/
ListListDemo.java
File metadata and controls
43 lines (35 loc) · 908 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package node;
public class ListListDemo {
/**
* add to front (start of the list)
*
* add to end (end of the list)
*/
int Count;
public Node Head = null;
public Node Tail = null;
public void AddToFront(Node node){
Node temp = Head; // save Head into temp
Head = node; // assign new node to head
Head.setNext(temp); // point new head next -> temp node
/**
* increase counter by 1
*/
this.Count++;
/**
* if the list was empty then Head and Tail should both point to the new node
*/
if (Count==1){
Tail = Head;
}
}
public void AddToEnd(Node node){
if(Count == 0){
Head = node;
}else {
Tail.setNext(node);
}
Tail = node;
Count++;
}
}