-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath.java
More file actions
55 lines (43 loc) · 1.02 KB
/
Path.java
File metadata and controls
55 lines (43 loc) · 1.02 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
import java.util.Stack;
public class Path implements Cloneable{
//should be implemented with a LinkedList
Stack<Integer> pathVertices;
double pathWeight;
public Path(Stack<Integer> pathVertices,double pathWeight){
this.pathVertices = pathVertices;
this.pathWeight = pathWeight;
}
public void addPath(Stack<Integer> path, double weight){
pathVertices.addAll(path);
this.pathWeight += weight;
}
public void addVertex(int v, double weight){
pathVertices.push(v);
this.pathWeight += weight;
}
public void removeVertex(double weight){
pathVertices.pop();
this.pathWeight -= weight;
}
public double getWeight(){
return this.pathWeight;
}
public Stack<Integer> getPath(){
return this.pathVertices;
}
public int pop(){
return this.pathVertices.pop();
}
public int peek(){
return this.pathVertices.peek();
}
public Path clone(){
try{
return (Path)super.clone();
}
catch(CloneNotSupportedException e)
{
throw new RuntimeException ("This class does not implement Cloneable");
}
}
}