Lab 14: Linked List

Introduction

You have been given the code:

  1. code in main that takes new numbers and puts it into the linked list

Step 1:

Display the list values (code is given), but you have to make a struct for the code to work.

        ----------        ----------

        |     |   |----->|     |   |------>.......

        |  5 |   |        |  6 |   |     

        ----------        ---------- 

       

The linked list should have a data field which is an integer and a pnext pointer to the next node.

Running the code should look like:

      Enter list numbers separated by space, followed by -1: 3 5 7 -1

      Menu options:

        1. Display the list number values.

        2. Display the sum of all numbers on the list.

        3. Delete the second node and return the data in the deleted node.

        4. Exit program

      Your choice -> 1

      The list number values are: 7 5 3

       

Step 2: ( 1 Point)

Display the sum of all numbers in the list

For this you have to write the getSumOfAllNumbers(.....) function

 

Running your program should look like this:

    Enter list numbers separated by space, followed by -1: 3 5 7 -1

    Menu options:

    1. Display the list number values.

    2. Display the sum of all numbers on the list.

    3. Delete the second node and return the data in the deleted node.

    4. Exit program

    Your choice -> 2

    The sum of all numbers on the list is: 15

Step 3: (Extra Credit 1 Point)

 Given three nodes delete the second node and return the data

 stored in it.

 

 So your linked list should look something like this:

 

           ______       ----------      ----------

           |    |    | ---->|    |    |----->|     |   |-------->

           | 1 |    |        | 2  |   |        | 3  |   |

           ----------       ----------      ----------

          

       

Running your program should look like this:

    Enter list numbers separated by space, followed by -1: 3 5 7 -1

    Menu options:

      1. Display the list number values.

      2. Display the sum of all numbers on the list.

      3. Delete the second node and return the data in the deleted node.

      4. Exit program

    Your choice -> 3

    Deleting second node.

    The data of the second node is: 5

    The list number values are: 7 3