想做什么!
我做了什么!
示例 Desired process, i want to implement
我的代码尚未
//function to add edge in graph
void addEdge(std::vector<char> adj[], char u, char v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
//function to print graph
void printGraph(std::vector<char> adj[], int V)
{
for (int v = 0; v < V; ++v)
{
std::cout << "\n Adjacency list of vertex "
<< v << "\n head ";
for (auto x : adj[v])
std::cout << "-> " << x;
printf("\n");
}
}
int main()
{
int numberOfUniquePeople = 0, numberOfPairs = 0, index = 0, newIndex
= 1;
std::vector<char> pair; //original pair of list
std::vector<char> uniqueElements; //unique number of people in
entire list
char c = '1';
while (c != '0')
{
int flag = 0;
std::cout << "Enter the pair : ";
std::cin >> c; //input for first person in pair
if (c == '0')
break;
else
pair.push_back(c);
//start check for unique people
for (auto i = uniqueElements.begin(); i != uniqueElements.end(); i++)
{
if(*i == c)
flag = 1;
}
if (flag != 1)
{
uniqueElements.push_back(c);
numberOfUniquePeople++;
}
//end check for unique people
flag = 0;
std::cin >> c; //input for second person in the pair
pair.push_back(c);
//start check for unique people
for (auto i = uniqueElements.begin(); i != uniqueElements.end(); i++)
{
if (*i == c)
flag = 1;
}
if (flag != 1)
{
uniqueElements.push_back(c);
numberOfUniquePeople++;
}
//end check for unique people
numberOfPairs++;
}
//creating graph
std::vector<char> adj[50];
for (auto i = pair.begin(); i != pair.end(); i++)
{
char c = *i;
char d = *(i+1);
addEdge(adj,c,d);
}
printGraph(adj, 50);
system("PAUSE");
}