Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
trh010
cs311_final_project
Commits
5ebfe2a4
Commit
5ebfe2a4
authored
Apr 15, 2014
by
trh010
Browse files
printing, adding vertex complete
parent
edfb606e
Changes
3
Show whitespace changes
Inline
Side-by-side
CS311_final_project/src/main/AdjacencyList.java
View file @
5ebfe2a4
...
...
@@ -11,7 +11,7 @@ public class AdjacencyList {
}
public
void
addNode
(
String
newWord
)
{
int
newHandle
=
adjList
.
size
()
-
1
;
int
newHandle
=
adjList
.
size
();
ArrayList
<
Integer
>
neighbors
=
findAndSetNeighbors
(
newWord
,
newHandle
);
Vertex
newVertex
=
new
Vertex
(
newWord
,
newHandle
,
neighbors
);
adjList
.
add
(
newVertex
);
...
...
@@ -31,11 +31,13 @@ public class AdjacencyList {
/**
* Tests if two strings should be neighbors to each other. Two string should
* be neighbors if
* be neighbors if
they have less that or equal to 2 differences (in order).
*
* @param a
* the first string
* @param b
* @return
* the second string
* @return true if the strings are related, false if they are not
*/
public
boolean
areRelated
(
String
a
,
String
b
)
{
if
(
a
.
length
()
!=
b
.
length
())
...
...
@@ -67,13 +69,14 @@ public class AdjacencyList {
}
public
String
toString
()
{
String
out
=
""
;
out
+=
"Handle Key | Neighbors \n"
;
out
+=
"------------------|------------\n"
;
String
Buffer
out
=
new
StringBuffer
()
;
out
.
append
(
"Handle Key | Neighbors \n"
)
;
out
.
append
(
"------------------|------------\n"
)
;
for
(
int
i
=
0
;
i
<
adjList
.
size
();
i
++)
{
out
+=
String
.
format
(
"%5d %5s"
,
i
,
adjList
.
get
(
i
).
getKey
())
+
" |\n"
;
out
.
append
(
String
.
format
(
"%5d %5s"
,
i
,
adjList
.
get
(
i
).
getKey
())
+
" | "
+
neighborsToString
(
adjList
.
get
(
i
))
+
"\n"
);
}
return
out
;
return
out
.
toString
()
;
}
}
CS311_final_project/src/main/Vertex.java
View file @
5ebfe2a4
...
...
@@ -11,7 +11,7 @@ public class Vertex {
public
Vertex
(
String
word
,
int
handle
,
ArrayList
<
Integer
>
neighbors
)
{
this
.
key
=
word
;
this
.
handle
=
handle
;
this
.
neighbors
=
ne
w
ArrayList
<
Integer
>()
;
this
.
neighbors
=
ne
ighbors
;
}
public
int
getHandle
()
{
...
...
CS311_final_project/src/test/5lw-s.dat
View file @
5ebfe2a4
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