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
12eb295b
Commit
12eb295b
authored
Apr 16, 2014
by
trh010
Browse files
Added better formatted output
parent
ec071867
Changes
2
Hide whitespace changes
Inline
Side-by-side
CS311_final_project/src/main/AdjacencyList.java
View file @
12eb295b
...
...
@@ -56,6 +56,19 @@ public class AdjacencyList {
return
out
.
toString
();
}
public
String
neighborsToString2
(
Vertex
v
)
{
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
).
getKey
();
out
.
append
(
" "
+
neighborKey
+
" ("
+
v
.
getEdges
().
get
(
i
).
weight
+
") "
);
if
(
i
%
6
==
5
)
out
.
append
(
"\n"
);
}
return
out
.
toString
();
}
public
Vertex
getVertexFromHandle
(
int
handle
)
{
return
adjList
.
get
(
handle
);
}
...
...
@@ -65,7 +78,6 @@ public class AdjacencyList {
if
(
s
.
equals
(
adjList
.
get
(
i
).
getKey
()))
return
i
;
}
return
-
1
;
}
...
...
CS311_final_project/src/main/Main.java
View file @
12eb295b
...
...
@@ -29,13 +29,18 @@ public class Main {
adjList
.
addNode
(
in
.
next
());
}
in
.
close
();
System
.
out
.
println
(
adjList
.
toString
());
//
System.out.println(adjList.toString());
}
catch
(
FileNotFoundException
e
)
{
System
.
err
.
println
(
"Error in opening the file: "
+
path
+
". Please check the file path."
);
}
}
/**
* Queries the user for a Word, then lists the word's neighbors. Continues
* this cycle if desired. Provides the functionality necessary for Part I of
* the assignment.
*/
public
void
queryUser
()
{
boolean
queryingUser
=
true
;
Scanner
in
=
new
Scanner
(
System
.
in
);
...
...
@@ -47,8 +52,11 @@ public class Main {
System
.
out
.
println
(
"Input string "
+
s
+
" is not in the dictionary"
);
else
System
.
out
.
println
(
adjList
.
neighborsToString
(
adjList
.
getVertexFromHandle
(
handle
)));
System
.
out
.
println
(
"The neighbors of "
+
s
+
" are:\n"
+
adjList
.
neighborsToString2
(
adjList
.
getVertexFromHandle
(
handle
)));
boolean
validResponse
=
false
;
while
(!
validResponse
)
{
...
...
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