Hello,
Here is a re-post of my previous message with the "code" tags. Sorry. 8) I'm attempting to use a FindNode function for both a Retrieve and Delete. Here are the function codes:
Code:bool SortedType::RetrieveItem(student& item) { if (FindNode (item)) // if item has been found (true) { item = current->info; return true; } return false; }Code:bool SortedType::FindNode(student item) { current = head; // start both pointers at front of list new_pointer = head; if (head->info.Key > item.Key) // not in list return false; if (head->info.Key == item.Key) // found and first in list return true; while ((current->next != NULL) && (current->next->info.Key <= item.Key)) current = current->next; // set current to point at next item new_pointer = current->next; // point new_pointer to next item if ((current == NULL) || (current->next->info.Key != item.Key)) return false; return true; }Basically what I'm noticing is when I attempt to do a delete it will only allow me to delete the first record and no others. Plus I notice that it "appears" to delete records that aren't there. When I start the program and immediately choose delete, it says,Code:bool SortedType:eleteItem(student& item) { if (FindNode (item)); // if item has been found (true) { if (new_pointer == head) // if item at front of list head = current->next; // point head where link points to else // else not first item in list current->next = new_pointer->next; delete new_pointer; // release this space if (new_pointer == tail) // if deleting last node tail = current; // set tail to previous node return true; // item is deleted from the list } return false; // item is not in the list }
"record 1000 has been deleted" when I never entered any records yet.
My Retrieve function appears to work in that it will not pull up any records as long as my list is empty but it too will not work with more than one record. I can easily retrieve the first record but any record afterwards it say "record 1000 could not be retrieved".
Somewhere my true/false values must somehow be screwing up. Can someone help me with my logic?
Thanks!
Ron



LinkBack URL
About LinkBacks


