forked from RainerYuan/Teamex4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphADT.java
More file actions
98 lines (85 loc) · 2.84 KB
/
Copy pathGraphADT.java
File metadata and controls
98 lines (85 loc) · 2.84 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
*
* A generic graph interface (DO NOT edit this file)
*
* (none of the methods throw exceptions)
*
* @author sapan (sapan@cs.wisc.edu)
*/
public interface GraphADT<E> {
/**
* Add new vertex to the graph
*
* Valid argument conditions:
* 1. vertex should be non-null
* 2. vertex should not already exist in the graph
*
* @param vertex the vertex to be added
* @return vertex if vertex added, else return null if vertex can not be added (also if valid conditions are violated)
*/
public E addVertex(E vertex);
/**
* Remove the vertex and associated edge associations from the graph
*
* Valid argument conditions:
* 1. vertex should be non-null
* 2. vertex should exist in the graph
*
* @param vertex the vertex to be removed
* @return vertex if vertex removed, else return null if vertex and associated edges can not be removed (also if valid conditions are violated)
*/
public E removeVertex(E vertex);
/**
* Add an edge between two vertices (edge is undirected and unweighted)
*
* Valid argument conditions:
* 1. both the vertices should exist in the graph
* 2. vertex1 should not equal vertex2
*
* @param vertex1 the first vertex
* @param vertex2 the second vertex
* @return true if edge added, else return false if edge can not be added (also if valid conditions are violated)
*/
public boolean addEdge(E vertex1, E vertex2);
/**
* Remove the edge between two vertices (edge is undirected and unweighted)
*
* Valid argument conditions:
* 1. both the vertices should exist in the graph
* 2. vertex1 should not equal vertex2
*
* @param vertex1 the first vertex
* @param vertex2 the second vertex
* @return true if edge removed, else return false if edge can not be removed (also if valid conditions are violated)
*/
public boolean removeEdge(E vertex1, E vertex2);
/**
* Check whether the two vertices are adjacent
*
* Valid argument conditions:
* 1. both the vertices should exist in the graph
* 2. vertex1 should not equal vertex2
*
* @param vertex1 the first vertex
* @param vertex2 the second vertex
* @return true if both the vertices have an edge with each other, else return false if vertex1 and vertex2 are not connected (also if valid conditions are violated)
*/
public boolean isAdjacent(E vertex1, E vertex2);
/**
* Get all the neighbor vertices of a vertex
*
* Valid argument conditions:
* 1. vertex is not null
* 2. vertex exists
*
* @param vertex the vertex
* @return an iterable for all the immediate connected neighbor vertices
*/
public Iterable<E> getNeighbors(E vertex);
/**
* Get all the vertices in the graph
*
* @return an iterable for all the vertices
*/
public Iterable<E> getAllVertices();
}