If I recall correctly *(Head+Pos) increments the pointer head by Pos values, If your nodes happen to be stored one after the other fine, but if you are allocating nodes dynamicly this cannot be taken for granted, the memory may be fragmented.
if (head!=NULL) //check for empty{ if (head->Value==Value) //is value at start ? { if (head->next!=NULL) //more than one node { temp=head->next; //remember the next node delete head; // delete data head = temp; //assign next node to head } else { delete head; head=NULL; //no nodes left } } else { currentnode=head->next; //prep oldnode=head; while (currentnode->next!=NULL) and (currentnode->Value!=Value) { oldnode=currentnode; currentnode = currentnode->next; //move onto next } if (currentnode->Value=Value) //we found it { if (currentnode->next!=NULL) // in middle { temp=currentnode->next; delete currentnode; oldnode->next = temp; } else { delete currentnode; // at end oldnode->next=NULL; //sort out pointers } } } //end else} // end if
I may have made a few mistakes, but the principle is sound.
Dynamic memory and pointers:
http://pw1.netcom.com/~tjensen/ptr/pointers.htm
,Jay
Edit: I new I'd made a mistake (one at least
).
[edited by - Jason Zelos on June 1, 2002 10:46:55 AM]