Solved: Write a program in C that does the following: a) (…

$30.00

Category:

Description

Solved: Write a program in C that does the following: a) (…

Write a program in C that does the following:

  1. a) (2 pts) Builds a simple linked list consisting of 100 nodes each of which contains a random integer between 50 and 100, inclusive. The list is to be built in main() and must be a local variable in main().
  2. b) (1 pt.) Include a programmer-defined function in the same program as item 1 above named printout(arg) that takes in the head pointer of the already-built linked list as an argument and prints out the contents of the linked list to the screen, starting from the head of the list to the tail. See the output below.

Node #0 contains 53

Node #1 contains 78

Node #2 contains 95

.
Node #20 contains 100

  1. c) (1 pt.) Include a programmer-defined function in the same program as item 1 above called sum() that adds up the contents of the data members of each node in the list, and prints out the total as follows:
    The sum total of all nodes in this list is <whatever the sum total is>
  2. d) (3 pts.) Include a programmer-defined function in the same program as item 1 above called reverse(arg) that takes in the head pointer of the already-built linked list as an argument and will physicallyreverse the order of the nodes in the list (i.e., the new head will be the old tail and the new tail will be the old head of the list). Use the function printout() to print out its contents now that it is reversed order. This does NOT mean that it will be read backwards, but rather, the now-reversed list will be read from head to tail!
  3. e) (2 pts.) Write a programmer-defined function called search(arg) that asks the user what number (between 50 and 99) she wishes to find in the linked list. The function searches for that number in the linked list and if found, prints out the position of the node in which it found the number requested. If the number requested is not within the proper range (50 to 99), then say so and give the user a second chance to enter it. If it is within the range, but it is not found, it should say that the search could not find that number in the list.

Set up the user entry in a loop so that the user can enter numbers repeatedly if she wants. That is, when the number is found (or not found), it will give her an opportunity to enter a new number. If the user no longer wants to use the program, she should enter -1.

For output, print out a line stating 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 #78

Note: The program submitted shall have all those functions described above and will execute them. The reason they are listed separately is that credit will be distributed among these functions.


error: Content is protected !!