You need to write code that will look for the number of pairs of identical elements so that they are counted only once.
Example: [1, 2, 1, 1] - "One pair of identical emails"
Here is my code that I wrote (I use the usual single-linked list):
void List::Check(int quan) { Node* tmp = Head, *tmp_1 = tmp; bool flag = false; int counter = 0; for (int i = 0; i < quan - 1; i++) { if (flag) { flag = false; tmp = tmp->next; continue; } flag = false; tmp_1 = tmp->next; for (int j = i + 1; j < quan; j++) { if (tmp->inf == tmp_1->inf) { counter++; flag = true; } if (flag) { break; } tmp_1 = tmp_1->next; } tmp = tmp->next; if (flag) { continue; } } switch (counter) { case 0: cout << "The list doesn't have the same values." << endl; break; case 1: cout << "The list has 1 pair of the same values." << endl; break; default: cout << "The list has " << counter << " pairs of the same values." << endl; break; } }
But there is a problem in it: it does not count if there is an unmatched number of emails and they are broken.
The same example: [1, 2, 1, 1]
When we find the first pair [ 1 , 2, 1 , 1], then how to implement the pass of the second el-pair, if it is not nearby? It can be explained on the basis of an array, I can not figure out how to do it, and on the Internet I did not find anything (