hi,
i am working(still)..on a linked list where nodes are assigned
and given an index number.
I am assigning the indexes incrementally according to the size
of the linked list.
Upon deletion (node chosen by index), I delete the node
and decrement the size, but when i return to print the list
I am getting junk when I encounter the spot where the
deleted node index was to be listed (and I crash).
Am I
a) assigning the index number incorrectly?
or
b) not re-assigning all indexes once a node is deleted.
-for example if I delete node 2 out of 3, should i re-assign
node 3 to be node 2?
here is where they are assigned
here is my delete functionCode:void ListofTeles::setdata() { char Name [MAX]; char Number[MAX]; long index = this->size+1; TeleEntry *Tele; cout << "Enter Name (Last,First) :"<< endl; cin >> Name; cout << "Enter Number :"<< endl; cin >> Number; Tele = new TeleEntry; strcpy (Tele->EntryNumber, Number); strcpy (Tele->EntryName, Name); Tele->index = index; this->Add(Tele); }
thanks to everyone who helps here...Code:void ListofTeles::Delete(int position) { TeleEntry *current, *dead=new TeleEntry; if (Head==NULL){cout << "List is Empty - Invalid Choice"<<endl; return;} else{ current = Head; while(current!=NULL){ cout<< "current index is " << current->index<< endl; if (current->index == position){ cout << current->EntryName<< " will be deleted"<< endl; if(current->index!=1){ current->Next=current->Next->Next; dead=current; delete dead; cout << "delete dead" << endl; dead=NULL; size--; cout << "size now" << size<<endl; return;} else {delete current; cout << "delete current is HEAD" << endl; size--; cout << "size now" << size<<endl; return;} } else current = current->Next; } } }



LinkBack URL
About LinkBacks



