-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFriendsApp.java
128 lines (120 loc) · 4.04 KB
/
FriendsApp.java
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package friends;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class FriendsApp {
static Scanner stdin = new Scanner(System.in);
public static void main(String[] args)
throws IOException {
System.out.print("Enter words file name => ");
String wordsFile = stdin.nextLine();
Scanner sc = new Scanner(new File(wordsFile));
Graph g = new Graph (sc) ;
System.out.println("Enter start name: ");
String start = stdin.nextLine();
System.out.println("Enter end name: ");
String end = stdin.nextLine();
ArrayList <String> ans1 = Friends.shortestChain ( g, start, end ) ;
if (ans1.isEmpty()) {
System.out.println("Emptylist");
}
for ( int i = 0 ; i < ans1.size(); i ++ ) {
if (i == ans1.size()-1 ) {
System.out.print(ans1.get(i));
} else {
System.out.print(ans1.get(i) + "--");
}
}
System.out.println();
System.out.println("Enter school name: ");
String school = stdin.nextLine();
ArrayList <ArrayList<String>> ans2 = Friends.cliques ( g, school) ;
if (ans2.isEmpty()) {
System.out.println("Emptylist");
}
for ( int i = 0 ; i < ans2.size(); i ++ ) {
System.out.print ("First clique: ");
// System.out.print("size: " + ans2.get(i).size() );
for ( int j = 0 ; j < ans2.get(i).size() ; j ++ ) {
if (j == ans2.get(i).size()-1 ) {
System.out.print(ans2.get(i).get(j) );
} else {
System.out.print(ans2.get(i).get(j) + "--");
}
}
System.out.println();
}
System.out.println("All connectors: ");
ArrayList <String> ans3 = Friends.connectors ( g ) ;
System.out.println("All connectors results: ");
if (ans3.isEmpty()) {
System.out.println("Emptylist");
}
for ( int i = 0 ; i < ans3.size(); i ++ ) {
if (i == ans3.size()-1 ) {
System.out.println(ans3.get(i));
} else {
System.out.print(ans3.get(i) + "--");
}
}
// // words appear one per line in input file
// // first line has number of words
// int numWords = Integer.parseInt(sc.nextLine());
// String[] allWords = new String[numWords];
// for (int i=0; i < allWords.length; i++) {
// allWords[i] = sc.nextLine().trim().toLowerCase();
// }
// sc.close();
//
// // build Trie
// TrieNode root = Trie.buildTrie(allWords);
// // print it for verification
// Trie.print(root, allWords);
// // do completion lists
// completionLists(root, allWords);
}
//
// TrieNode root = Trie.buildTrie(allWords);
// // print it for verification
// Trie.print(root, allWords);
// // do completion lists
// completionLists(root, allWords);
//}
//
// private static void shortestChain(TrieNode root, String[] allWords) {
// System.out.print("\ncompletion list for (enter prefix, or 'quit'): ");
// String prefix = stdin.nextLine().trim().toLowerCase();
// while (!"quit".equals(prefix)) {
// ArrayList<TrieNode> matches = Trie.completionList(root, allWords, prefix);
// printMatches(matches, allWords);
// System.out.print("\ncompletion list for: ");
// prefix = stdin.nextLine().trim().toLowerCase();
// }
// }
//
// private static void cliques (Graph g, String allWords) {
//// (ArrayList<TrieNode> matches, String[] allWords) {
// if (matches == null) {
// System.out.println("No match");
// return;
// }
// System.out.print(allWords[matches.get(0).substr.wordIndex]);
// for (int i=1; i < matches.size(); i++) {
// System.out.print(","+allWords[matches.get(i).substr.wordIndex]);
// }
// System.out.println();
// }
//
// private static void connectors(Graph g) {
//// shortestChain(TrieNode root, String[] allWords) {
// System.out.print("\ncompletion list for (enter prefix, or 'quit'): ");
// String prefix = stdin.nextLine().trim().toLowerCase();
// while (!"quit".equals(prefix)) {
// ArrayList<TrieNode> matches = Trie.completionList(root, allWords, prefix);
// printMatches(matches, allWords);
// System.out.print("\ncompletion list for: ");
// prefix = stdin.nextLine().trim().toLowerCase();
// }
// }
}