So I still can't seem to find this seg fault when compiling on ubuntu. I ran valgrind and appears it's coming from this function. What is a good way to find these? I tried drawing it out on paper but couldn't seem to pick up my pointer errors. Here is my code, any advice is much appreciated, thanks!
bool Ordered_list::remove(int data){
if(list == NULL)
returnfalse;
// if head node is has data equal to data then forward head
if(list->data == data){
node *temp = list;
list = list->next;
delete temp;
returntrue;
}else{
node *temp = list;
while(temp->next != NULL){
if(temp->next->data == data){ // if temp next data is equal to data then remove it
node *temp = temp->next;
temp->next = temp->next->next;
delete temp;
returntrue;
}
temp = temp->next;
}
returnfalse; // data is not available in list
}
}
@townage15 and @helios, I am interested to learn this notation ->
What is it called and what is it more often used for ? If you could share some of your knowledge it would be great. Thanks
struct foo { int member; } bar;
// To access bar's member, I write:
bar.member;
// If I have a pointer to foo:
foo* baz = &bar;
// I can access the pointed-to object's member using
baz->member;