okay, so i was asked to do a recursive search on a singly linked list. Problem is the function works to search only one node, the first node in the list and display it, but crashes on searching any other than the first. Please take a look at my code.
and this is what i used to call the function simple case.void linkedList::recursiveSearch(int key)
{
node* temp = start_ptr;
if(temp == NULL)
cout<<"No list to search from, Please try again"<<endl;
else if(temp->getData.empId == key)
{ cout<<"Info for this ID# is as follows: "<<endl;
cout << "First Name : " << temp->getData.firstName << endl;
cout << "Last Name : " << temp->getData.lastName << endl;
cout << "Employee ID : " << temp->getData.empId << endl;
cout << "Employment type: " << temp->getData.empType<<" time" << endl;
cout << "Salary :$" << temp->getData.salary << endl;
cout << endl;
}
else if(temp->getData.empId != key)
{
recursiveSearch(key);temp = temp->nxt;
}
}
case 6:
system("cls");
int key;
cout<<"enter key id record to search for: "<<endl;
cin>>key;
linky.recursiveSearch(key);
break;
OK CORRECTED IT WITHOUT YA'LL HELP -.- anyways where is the solution lol...
changes to Cpp file
case 5:
int id;
cout<<"enter key id record to search for: "<<endl;
cin>>id;
caller.rSearchy(caller.getStart(), id, 0);
break;
changes to the header file
and added also in the header filevoid linker::rSearchy(node* n, int id, int count)
{
if(count == 0);
node* temp = n;
if(temp == NULL)
cout<<"This is an empty list, Please Store some data in it first."<<endl;
else if(temp->data.ID == id)
{
cout<<"The Information for the searched ID# is:"<<endl;
cout << "Employee ID : " << temp->data.ID << endl;
cout << "First Name : " << temp->data.firstname << endl;
cout << "Last Name : " << temp->data.lastname << endl;
cout << "Employment type: " << temp->data.employType<<" time" << endl;
cout << "Salary :$" << temp->data.salary << endl;
cout << endl;
}
else if(n->data.ID != id)
{
count = count + 1;
temp = temp->next;
rSearchy(temp, id, count);
}
}
and in the prototypenode* linker::getStart()
{
return head;
}
node* getStart();