Question

Write a function to accept a header of a sorted linked and a name which can...

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.

Homework Answers

Answer #1


/*
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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Take the orderhw.c file and modify the code to build a linked list that is sorted...
Take the orderhw.c file and modify the code to build a linked list that is sorted by the address field not the name field as it is currently written! Using the following code void prntlist(LISTREC *liststart)            /*argument is a pointer to type LISTREC*/ {     /*begin function*/    while (liststart != NULL)        { /*begin while*/            printf("%s\n",liststart->info.name);            liststart = liststart->link;        } /*end while*/    }   /* end function prntlist*/...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked...
Create a header file (lastname_employeerec.h) that defines an employee data structure (sEMPLOYEE) that can be linked onto a linked list. The data structure should have the following fields: a. First Name (firstName) b. Last Name (lastName) c. Employee ID (id) d. Start Year (startYear) e. Starting Salary (startSalary) f. Current Salary (currentSalary) g. next Create a library of functions that operate on this data structure. The source code for the functions should be in lastname_employeerec.c and the function prototypes should...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
1. Prompt the user for a name 2. Call a function that can accept the name...
1. Prompt the user for a name 2. Call a function that can accept the name that the user entered.3. In the function, reverse the name and return the new value to the function call.4. Output to the console "Hi <username>, do you mind if I call you <reversed user name>"? (replace <username> and <reversed user name> with the proper values).
/* Write a function that looks for a particular person in their respective linked list The...
/* Write a function that looks for a particular person in their respective linked list The only place you need to write code is the "find" method in the linked list class */ #include <bits/stdc++.h> using namespace std; string ltrim(const string &); string rtrim(const string &); #define BUFFLEN 10 /* Each "person" is defined by their name, zipcode, and their pet's name. Persons are hashed by their zipcode. */ //---------------------------------------------------------------------------- /* function declarations ------------------------*/ int computeKey(int); void add_to_buffer(string,int,string); void find_in_buffer(int);...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted...
Data Structures using C++ Searching a Linked List Here are the declarations for a simple unsorted linked list of ints that ends in a null pointer. //=============================================================== class Cell { friend class UList; private: int data; Cell* next; Cell( int dt, Cell* nx=nullptr ) : data(dt), next(nx) {} }; //=============================================================== class UList { private: Cell* head = nullptr;    // stationary head pointer. Cell* scan = nullptr;          // for walking down the List. Cell* follow = nullptr; public: void find( int...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
IN PYTHON: Write a program where the user enters a name. Using the read function, check...
IN PYTHON: Write a program where the user enters a name. Using the read function, check to see if the name is in the text document. If it is, respond back to the user the name is found within the list
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Write a program that sorts the content of a map by Values. Before we start, we...
Write a program that sorts the content of a map by Values. Before we start, we need to check the explanation of Java Map Interface and Java LinkedHashMap. This program can be implemented as follows: 1. Create a LinkedHashMap class <String (Country), String(Capital)> that stores Capitals of FIVE countries. 2. Use sortMap() for receiving content of the created class of LinkedHashMap and reorder it in a sorted Map. (sort in natural order). 3. You need to transfer the map into...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Consider insertsort. Suppose that the input array A has 1% probability to be monotonically decreasing. Show...
    asked 6 minutes ago
  • Your company is thinking of introducing a Bring Your Own Device (BYOD) policy. You have been...
    asked 13 minutes ago
  • Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
    asked 15 minutes ago
  • Suppose the number of cars in a household has a binomial distribution with parameters n =...
    asked 18 minutes ago
  • HR needs some information on the new interns put into a database. Given an id, email,...
    asked 39 minutes ago
  • Problem solving strategies Questions years = input("Enter a number of years and I'll tell you how...
    asked 43 minutes ago
  • Calculate ?Hrxn for the following reaction: CH4(g)+4Cl2(g)?CCl4(g)+4HCl(g) Use the following reactions and given ?H?s. C(s)+2H2(g)?CH4(g)?H=?74.6kJC(s)+2Cl2(g)?CCl4(g)?H=?95.7kJH2(g)+Cl2(g)?2HCl(g)?H=?184.6kJ Express...
    asked 50 minutes ago
  • ASCII (American Standard Code for Information Interchange) has an encoding for every character of the alphabet,...
    asked 1 hour ago
  • Is home confinement with electronic monitoring a deterrent? Are there negatives to being confined to one’s...
    asked 1 hour ago
  • Social hostility can have severe lasting effects of interperpersonal relationship during our adolescence years, which if...
    asked 1 hour ago
  • - A series RLC circuit has R=15 ?, L=1.5 H, and C=15 ?F. (a) For what...
    asked 1 hour ago
  • TV Circuit has 30 large-screen televisions in a warehouse in Erie and 60 large-screen televisions in...
    asked 1 hour ago