| CptSJP (1) | |
|
Hi I'm writing a program that takes a randomly generated vector and checks that vector to see if there are any repeated elements. If there are, I am to delete those elements.I can't declare any new vectors, I can't change the order of any non repeated numbers and I can only use the vector functions pop_back(), push_back(), and .size(). ex. vector generated by program: 3 5 1 1 4 2 4 1 3 5 vector after it goes through the program: 3 5 1 4 2 my program compiles (using g++ -ansi - pedantic -Wconversion) and it runs and outputs everything it supposed to but it prints out a whole block of text starting with "*** glib detected ***. What does this mean? here is the part of my code where I think I went wrong if you need it. Thank you for taking the time to read this int holder = 0; for(int i = 0; i < static_cast<int>(hasRepeats.size());i = i + 1) { for(int j = static_cast<int>(hasRepeats.size()) - 1; j >= 0; j = j - 1) { if(j != i) { if(hasRepeats[i] == hasRepeats[j] && j == static_cast<int>(hasRepeats.size()) - 1) { hasRepeats.pop_back(); } else if(hasRepeats[i] == hasRepeats[j] && j != static_cast<int>(hasRepeats.size()) - 1) { for(int e = j; e < static_cast<int>(hasRepeats.size()); e = e + 1) { holder = hasRepeats[e]; hasRepeats[e] = hasRepeats[e + 1]; hasRepeats[e + 1] = holder; } hasRepeats.pop_back(); } } } } | |
|
|
|