Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your assigned task is to write the code for the insert_name_list(...) subprogram, whose prototype is shown below and is defined in the name_list.h header file.

Your assigned task is to write the code for the "insert_name_list(...)" subprogram, whose prototype is shown below and is defined in the name_list.h header file.

void insert_name_list(sNAME_LIST *name_list, // The linked list of names. sNODE *node ); // The node containing the name. 

The purpose of the "insert_name_list(...)" subprogrm is to build a single-linked list of names, with the following provisions:

  • A given name is inserted in the "name_list" ONLY if the name is not already present in the list.
  • If a name is already present in the list, then the "insert_name_list(...)" routine simply discards the given node by freeing it's storage.
  • A new node is always inserted at the end of the list, that is, it is appended to the list.
  • Stop searching the list of names as soon as the target name is found to be present in the list.
  • An appropriate error message is printed if the "name_list" does not exist, or is undefined.

Compile and execute the project to test your code. You MUST NOT alter any of the given code. Your list must be constructed so that it will work with the given source code.

The following files define a linked list of names (First Name, Last Name) written in C, along with other header (.h) and code (.c) files, as explained below:

names_list.h

The header file defining the structure and subprograms (Functions and Subroutines) of the "name_list" linked list.

names_list.c

The complete source code for the subprograms prototyped in the names_list.h header file. All except for the source code for the "insert_name_list(...)" subprogram. In the Tasks Section, you will be asked to write the code for this subprogram.

rm_library.h and rm_library.c

The header and source code files for the definitions and constants used in the given subprograms. RM stands for Rick Magnotta, and the "rm_library" contains some definitions that I found to be quite useful in writing C code. You are free to use these definitions in the code that you write, or not.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions