-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.java
More file actions
67 lines (67 loc) · 1.33 KB
/
List.java
File metadata and controls
67 lines (67 loc) · 1.33 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
//List.java
//Used for holding the different options for the Room class
class List{
private class Node{
Node next;
String str;
Room destination;
}
private Node head;
public int size=0;
public int returnSize(){
return size;
}
public void printOptions(){
Node nd = head;
while(nd!=null){
System.out.println("\t"+nd.str);
System.out.println("\t\t Goes to: "+nd.destination.getTag());
nd=nd.next;
}
}
public void print(){
Node nd = head;
StringStack stk = new StringStack();
while(nd!=null){
stk.push(nd.str);
nd=nd.next;
}
if(returnSize()!=0){System.out.println("What do you do?");}
while(!stk.isEmpty()){
stk.pop();
}
}
public void updateHeadRm(Room r){
head.destination=r;
}
public void insert(String s, Room r){
size++;
if(head==null){
//if theres no head, make it
head=new Node();
head.str=s;
head.destination=r;
}
else{
//otherwise make a new node and have it point to the head, then make the just added one the head
Node x = new Node();
x.destination=r;
x.str=s;
x.next=head;
head=x;
}
}
//z here is the letters a,b,c,... for the options
public Room findOptionInfo(char z){
Node tmp = head;
while(tmp!=null){
if(tmp.str.length()>0){
if(tmp.str.charAt(0)==z){
return tmp.destination;
}
}
tmp=tmp.next;
}
return null;
}
}