-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
131 lines (123 loc) · 5.11 KB
/
main.cpp
File metadata and controls
131 lines (123 loc) · 5.11 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
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
129
130
131
#include <iostream>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include "ListGraph.cpp"
#include "MatrixGraph.cpp"
#include "Project3ReturnMap.cpp"
using namespace std;
int main() {
// Map that stores artists and their connections
unordered_map<string, set<string>> daMap = returnMap();
cout << "Map size = " << daMap.size() << endl;
//Check artist name
cout << "Welcome to Custer, Ethan, and Isaac's Spotify project!" << endl;
bool runLevel = true;
// Loop to run project
while (runLevel == true) {
cout << "Please enter the name of the artist you want to check: ";
string artist;
int levelNum;
getline(cin, artist);
cout << artist << endl;
cout << "Please enter how many iterations you want to go through for this project:" << endl;
cin >> levelNum;
cout << "Please enter 1 for Adjacency Matrix and 2 for Adjacency List:" << endl;
int menuSelect;
cin >> menuSelect;
cin.ignore(256, '\n');
// Menu for determining which data structure to run
if (menuSelect == 1) {
MatrixGraph lookatThisGraph(daMap);
queue<string> qu;
//Checks if artists exists in map
bool isInMap = lookatThisGraph.CheckArtist(artist);
//Vector of strings for each level
vector<vector<string>> levelStore(levelNum);
if (isInMap) {
qu.push(artist);
unordered_set<string> alreadyIncluded;
//Uses queue to store data for each level, and then uses a set to see if the artists was included in a previous generation
for (int i = 0; i < levelNum; i++) {
if (!qu.empty()) {
int quSize = qu.size();
for (int j = 0; j < quSize; j++) {
set<string> daSet = lookatThisGraph.GetAdjacents(qu.front());
for (auto it = daSet.begin(); it != daSet.end(); it++) {
if (alreadyIncluded.find(*it) == alreadyIncluded.end() && *it != artist) {
alreadyIncluded.insert(*it);
qu.push(*it);
levelStore[i].push_back(*it);
}
}
qu.pop();
}
}
}
}
else {
cout << "Artist not in data" << endl;
continue;
}
set<string> daSet = lookatThisGraph.GetAdjacents(artist);
//Prints artists in set
for (int i = 0; i < levelStore.size(); i++) {
cout << "Level " << i + 1 << ": " << endl;
if (levelStore[i].size() == 0) {
cout << "There are no more artists to include!" << endl;
break;
}
for (string y : levelStore[i]) {
cout << y << endl;
}
}
} else if (menuSelect == 2) {
//This section is the same as above, using the Adjacency List instead of the adjacency matrix
ListGraph lookatThisGraph(daMap);
queue<string> qu;
bool isInMap = lookatThisGraph.CheckArtist(artist);
//Vector of strings for each level
vector<vector<string>> levelStore(levelNum);
if (isInMap) {
qu.push(artist);
unordered_set<string> alreadyIncluded;
for (int i = 0; i < levelNum; i++) {
if (!qu.empty()) {
int quSize = qu.size();
for (int j = 0; j < quSize; j++) {
set<string> daSet = lookatThisGraph.GetAdjacents(qu.front());
for (auto it = daSet.begin(); it != daSet.end(); it++) {
if (alreadyIncluded.find(*it) == alreadyIncluded.end() && *it != artist) {
alreadyIncluded.insert(*it);
qu.push(*it);
levelStore[i].push_back(*it);
}
}
qu.pop();
}
}
}
}
else {
cout << "Artist not present in data";
break;
}
set<string> daSet = lookatThisGraph.GetAdjacents(artist);
for (int i = 0; i < levelStore.size(); i++) {
cout << "Level " << i + 1 << ": " << endl;
if (levelStore[i].size() == 0) {
cout << "There are no more artists to include!" << endl;
break;
}
for (string y : levelStore[i]) {
cout << y << endl;
}
}
}
else if (menuSelect == 3) {
cout << "Goodbye!" << endl;
runLevel = false;
}
}
}