Hello, I usually don't complain too much. But this time I am getting mad. I just wrote a linked list, where
1. If the value was not present before in the list, it will be added. In this case, there is a capacity. If the new value increases the list size more than capacity, then the eldest one will be deleted.
2. If the value was present in the list, it will be added on the top of the list, and the old value have to be removed.
I am done with all of the parts, but I can't remove the old value.... my code goes below:
void RList::add(int newNum) {
lNode *h, *t, *p=NULL, *c;
bool run=false;;
if(!numberExists(newNum)) {
if(!(size<capacity)) {
throw invalid_argument ("RedialList::add() Not enough place");
}
size++;
}
else run=true;
if(head==NULL) {
h=new lNode(newNum, NULL);
head=h;
return;
}
h= new lNode(newNum, head);
head=h;
if(numberExists(newNum) && run) {
c=head;
for(p=head->next;;p=p->next;) {
if(p->phnNo==newNum){
c=p->next;
delete c;
return;
}
}
}
}
so far i can see, the problem is in this code:
if(numberExists(newNum) && run) {
c=head;
for(p=head->next;;p=p->next;) {
if(p->phnNo==newNum){
c=p->next;
delete c;
return;
}
}
}