Write a function to accept a header of a sorted linked and a name which can be used as a key. If the key is found then add the record to the linked list using pointer(s). Do not write complete program. Write just one function.
I just need a function that can demonstrate the prompt above.
/*
this function inserts name in sorted list
*/
struct node* insert_in_sortedlist(struct node* head , string
name)
{
struct node* temp=new node;
struct node* prev=new node;
struct node* new_node=new node;
new_node->name=name;
new_node->next=NULL;
temp=head;
while(temp->name!=name)
{
prev=temp;
temp=temp->next;
}
prev->next=new_node;
new_node->next=temp;
return head;
}
/*
this function returns true or false and if it is true then it
passes head of list and name that is to be inserted to
insert_in_sortedlist()
function from main function and if it is false then it prints "not
found" in main function.
*/
bool search(struct node* head , string name)
{
if(head==NULL)
return false;
struct node *temp= new node;
temp=head;
while(temp!=NULL)
{
if(temp->name==name)
return true;
temp=temp->next;
}
return false;
}
Get Answers For Free
Most questions answered within 1 hours.