Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
trh010
cs311_final_project
Commits
59292373
Commit
59292373
authored
Apr 21, 2014
by
trh010
Browse files
Vertex now extends HeapElt
parent
d55ac7c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
CS311_final_project/src/main/AdjacencyList.java
View file @
59292373
...
...
@@ -21,7 +21,7 @@ public class AdjacencyList {
ArrayList
<
Edge
>
neighbors
=
new
ArrayList
<
Edge
>();
for
(
int
i
=
0
;
i
<
adjList
.
size
();
i
++)
{
Vertex
testVertex
=
adjList
.
get
(
i
);
int
numDifferences
=
numDifferences
(
testVertex
.
get
Key
(),
newWord
);
int
numDifferences
=
numDifferences
(
(
String
)
testVertex
.
get
Record
(),
newWord
);
if
(
2
>=
numDifferences
)
{
int
weight
=
0
;
if
(
numDifferences
==
1
)
...
...
@@ -55,7 +55,7 @@ public class AdjacencyList {
StringBuffer
out
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
v
.
getEdges
().
size
();
i
++)
{
int
neighborHandle
=
v
.
getEdges
().
get
(
i
).
toVertex
;
String
neighborKey
=
adjList
.
get
(
neighborHandle
).
get
Key
();
String
neighborKey
=
(
String
)
adjList
.
get
(
neighborHandle
).
get
Record
();
out
.
append
(
neighborKey
+
" ("
+
v
.
getEdges
().
get
(
i
).
weight
+
"), "
);
}
return
out
.
toString
();
...
...
@@ -65,7 +65,7 @@ public class AdjacencyList {
StringBuffer
out
=
new
StringBuffer
();
for
(
int
i
=
0
;
i
<
v
.
getEdges
().
size
();
i
++)
{
int
neighborHandle
=
v
.
getEdges
().
get
(
i
).
toVertex
;
String
neighborKey
=
adjList
.
get
(
neighborHandle
).
get
Key
();
String
neighborKey
=
(
String
)
adjList
.
get
(
neighborHandle
).
get
Record
();
out
.
append
(
" "
+
neighborKey
+
" ("
+
v
.
getEdges
().
get
(
i
).
weight
+
") "
);
if
(
i
%
6
==
5
)
...
...
@@ -80,7 +80,7 @@ public class AdjacencyList {
public
int
findStringHandle
(
String
s
)
{
for
(
int
i
=
0
;
i
<
adjList
.
size
();
i
++)
{
if
(
s
.
equals
(
adjList
.
get
(
i
).
get
Key
()))
if
(
s
.
equals
(
adjList
.
get
(
i
).
get
Record
()))
return
i
;
}
return
-
1
;
...
...
@@ -92,7 +92,7 @@ public class AdjacencyList {
out
.
append
(
"------------------|------------\n"
);
for
(
int
i
=
0
;
i
<
adjList
.
size
();
i
++)
{
out
.
append
(
String
.
format
(
"%5d %5s"
,
i
,
adjList
.
get
(
i
).
get
Key
())
.
format
(
"%5d %5s"
,
i
,
adjList
.
get
(
i
).
get
Record
())
+
" | "
+
neighborsToString
(
adjList
.
get
(
i
))
+
"\n"
);
}
return
out
.
toString
();
...
...
@@ -108,8 +108,6 @@ public class AdjacencyList {
}
getVertexFromHandle
(
startingVertex
).
setDist
(
0
);
}
private
ArrayList
<
Integer
>
findPath
(
int
start
,
int
end
,
ArrayList
<
Integer
>
path
){
...
...
CS311_final_project/src/main/Vertex.java
View file @
59292373
package
main
;
import
heap.HeapElt
;
import
java.util.ArrayList
;
public
class
Vertex
{
public
class
Vertex
extends
HeapElt
{
private
String
key
;
private
int
handle
;
private
ArrayList
<
Edge
>
edges
;
private
int
pred
;
private
int
dist
;
public
Vertex
(
String
word
,
int
handle
,
ArrayList
<
Edge
>
neighbors
)
{
this
.
key
=
word
;
this
.
record
=
word
;
this
.
handle
=
handle
;
this
.
edges
=
neighbors
;
pred
=
-
1
;
...
...
@@ -42,10 +41,6 @@ public class Vertex {
this
.
handle
=
handle
;
}
public
String
getKey
()
{
return
key
;
}
public
void
addEdge
(
int
n
,
int
weight
)
{
edges
.
add
(
new
Edge
(
n
,
weight
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment