-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.pde
More file actions
70 lines (60 loc) · 1.42 KB
/
Copy pathlist.pde
File metadata and controls
70 lines (60 loc) · 1.42 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
68
69
70
//CIRCULAR LIST
class CircularList {
int size =0;
Node head=null;
Node tail=null;
public void addNodeAtStart(PVector coord){
System.out.println("Adding node " + coord + " at start");
PVector paux = new PVector (0, 0, 0);
paux.x = coord.x;
paux.y = coord.y;
paux.z = coord.z;
Node n = new Node(paux);
if(size==0){
head = n;
tail = n;
n.next = head;
}else{
Node temp = head;
n.next = temp;
head = n;
tail.next = head;
}
size++;
}
public PVector elementAt(int index){
if(index>size){
return null;
}
Node n = head;
while(index-1!=0){
n=n.next;
index--;
}
return n.tarCoord;
}
public void print(){
System.out.print("Circular Linked List:");
Node temp = head;
if(size <= 0){
System.out.print("List is empty");
}else{
do {
System.out.print(" " + temp.tarCoord);
temp = temp.next;
}
while(temp!=head);
}
System.out.println();
}
public int getSize(){
return size;
}
}
class Node {
PVector tarCoord = new PVector (0, 0, 0);
Node next;
Node(PVector tc){
tarCoord = tc;
}
}