Quote
a.out(12744) malloc: *** error for object 0x7fff5fbff9a0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
I don't really understand the error message. But in my code the error pertains to lines 38 and 39. Can someone take a seconds and give me some advice?
#include <iostream>
#include <list>
using namespace std;
int maxList(list<int> array, int x);
int main() {
int tempInt;
char tempChar;
list<int> L;
cout << "\nEnter an array of ints, and end it with a # sign" << endl;
cin >> tempChar;
while(tempChar != '#') {
tempInt = atoi(&tempChar);
L.push_back(tempInt);
cin >> tempChar;
}
maxList(L, 2);
return 0;
}
int maxList(list<int> array, int x) {
if(*array.begin() == x) {
cout << "Found" << endl;
return 0;
}
if(*array.begin() != x) {
array.pop_front();
maxList(array, x);
}
if(array.begin() == array.end()) {
cout << "Doesn't exist";
return 1;
}
}


Sign In
Create Account


Back to top









