Im making a doubly linked list program. I am having problems with the menu uption INSERT_AFTER. I think using the FIND function is the right go at it but I just dont seem to get it right. (The functions are working fine, I just need help with, how to call the function) Can someone help please?
void FIND(element* head, int searchedNumber) {
current = head;
while (current->next != NULL) {
if (current->key == iskanoSt) {
cout << "Num" << searchedNumber<< " found.\n";
}
current = current->next;
}
}
void INSERT_AFTER(element * &elem, element* new_el) {
new_el->prev = elem;
new_el->next = elem->next;
elem->next = new_el;
if (new_el->next != NULL) {
new_el->next->prev = new_el;
} else
tail= new_el;
}
main (){
....
if (choosen== 3) {
cout<< "insert num:";
element*f=new element;
cin >> f->key; // The number i insert is working fine. I dont know how to
//find the element that
//that I have to insert after. I tryed to insert the function I
//wrote above, but I dont know how or
//If it is ever correct.
cout<<"After elemen:";
cin >> searchedNum;
FIND(head, searchedNum);
INSERT_AFTER(?????,f);
}
Aucun commentaire:
Enregistrer un commentaire