Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Basic C program: Linked lists, searching and sorting A) Write a program (Program A) that creates a linked list of 100 nodes, each containing a

Basic C program: Linked lists, searching and sorting

A)

Write a program (Program A) that creates a linked list of 100 nodes, each containing a random positive integer between 0 and 99. The program must provide the user with four choices: Build the list; Print out the list; Search the list; and Quit. Hint: Use aswitch structure in a while loop, where each of the first three choices in the switchleads to a UFD that does the work (Build, Print out or Search the list). Of course, Quit is trivial and does not need a UFD.

1) Build the list and assigns a value (random integer between 0 and 99) to each node.

2) Prints out the contents of the list to screen. For example: (you can either start from 0 or from 1 it doesnt matter)

 Node #1 contains the value of 71 Node #2 contains the value of 36 Node #3 contains the value of 19 

. . .

 Node #100 contains the value of 27 

3) Asks the user what number she wishes to find in the list and searches for thefirst instance of that number. The search must return (i.e., print to screen) the node number in which the entry was found, so the program must keep count of the nodes it has visited. Assume the list is unordered (which of course, it is). If the number is not found in the list, it must say: The search has failed.

For output, the program must print out one line indicating that the value sought was found in the nth node. For example:

 Please enter the number to be sought in the list: >> 15 The number 15 was found in node #81 

B)

Write a second program (Program B) that builds a contiguous list (i.e., array?based), also of 100 elements (cells), each containing a random integer between 0 and 99. You encouraged to re?use as much code from Program A as you wish (this is called code re?sue and it is a good thing). This program must:

1) Build the contiguous list (i.e., the properly populated array).

2) Print out the contents of the list. Use the same output format you used for part A.2 except call it a cell and not a node.

3) Sort the list using the insertSort algorithm.

4) Print out the list automatically after it has been sorted. Use the same printout format

as in part B.2 above.

Note: These are to be two separate programs and not one program in two separate files!! The names of the files you submit should be

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

c. How is trust demonstrated?

Answered: 1 week ago

Question

Have issues been prioritized?

Answered: 1 week ago

Question

d. How will lack of trust be handled?

Answered: 1 week ago