There is a single-linked list in which the user enters items from the keyboard. After forming the list, a function is launched that should check that the elements do not repeat. I compare the first element with all, then the second with all and so on. But it turns out that when an element is compared to itself, repetitions are found. How to avoid it?
bool Check(Link* linkMain, int count) { Link* first; Link* temp; for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { if (linkMain->data == temp->data) { cout << "Элементы повторяются!" << endl; return true; } temp = temp->next; } linkMain = linkMain->next; temp = first; } return false; }