1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
int linkedlist:: remNode(trans*& head, char inv[]){
trans *prev, *curr, *tmp;
if (head==NULL){
cout<<"Nothing to remove in the list"<<endl;
return -1;
}
else{
curr=head;
prev=head;
while(curr!=NULL){
if(curr==head){
if(strcmp(inv, curr->inv_num)==0){
head=curr->next;
strcpy(head->hware_item_bar, curr->next->hware_item_bar);
strcpy(head->inv_num, curr->next->inv_num);
head->qt_pchase=curr->next->qt_pchase;
head->total_price=curr->next->total_price;
delete curr;
return 0;
}
else
return -1;
}
else if (head->next->next==NULL){
if(strcmp(inv,head->next->inv_num)==0){
curr=head->next;
strcpy(curr->hware_item_bar, head->hware_item_bar);
strcpy(curr->inv_num, head->inv_num);
curr->qt_pchase=head->qt_pchase;
curr->total_price=head->total_price;
delete head;
head=curr;;
strcpy(head->hware_item_bar, curr->hware_item_bar);
strcpy(head->inv_num, curr->inv_num);
head->qt_pchase=curr->qt_pchase;
head->total_price=curr->total_price;
return 0;
}
else
return -1;
}
else if(curr){
if(strcmp(inv,curr->inv_num)==0){
prev->next=curr->next;
strcpy(prev->next->hware_item_bar, curr->next->hware_item_bar);
strcpy(prev->next->inv_num, curr->next->inv_num);
prev->next->qt_pchase=curr->next->qt_pchase;
prev->next->total_price=curr->next->total_price;
delete curr;
return 0;
}
else
return -1;
}
prev=curr;
curr=curr->next;
}
}
}
|