Lab 13: Linked Lists

Quiz:

The quiz will be available during the first 5 minutes of lab: Your lab TA will tell you the quiz password for your section. You may use either one of the lab machines or your own laptop. For the lab computers your account name and password are the same as your UIC NetID and password.

Select Your Lab Time: 9am, 10am, 11am, 12pm, 1pm, 2pm, 3pm, 4pm, 5pm


Zybooks 12.13

  • In this lab you will work on functions that involve the use of linked lists

  • **Nodes are prepended into each list NOT APPENDED**

  • The three functions you will need to implement are:

    • Problem #1: int findNumber(Node *pHead, int valueToFind) (1 point)

      • Write a function that traverses a list and looks for a valueToFind

      • If the valueToFind is found return the position of that node on the list if it isn't found return -1

      • Assume the linked list has nodes on it

      • Output Example:

Enter as many integers > 0 as you would like for the first list

followed by the value -1.


The numbers are: 1 2 3 4 -1

Enter as many integers > 0 as you would like for the second list

followed by the value -1.


The numbers are: 1 2 3 4 -1

Please enter the problem you want to attempt: 1


Please enter the number you are looking for in list one: 4

Numbers position in the list: 0

    • Problem #2: void numbersInBothLists(Node *pHead, Node *pHead2) (1 point)

      • Traverse the first list

      • Display elements only if it's in the second list

        • **Lists may or may not be the same length**

        • Assume the linked list has nodes on it

      • Output Example:

Enter as many integers > 0 as you would like for the first list

followed by the value -1.


The numbers are: 4 5 6 8 -1

Enter as many integers > 0 as you would like for the second list

followed by the value -1.


The numbers are: 1 2 3 8 -1

Please enter the problem you want to attempt: 2


Numbers in both lists: 8

    • Problem #3: void numbersInBothAndPosition(Node *pHead, Node *pHead2) (1 Extra Credit Point)

      • Display only the nodes that have the same data and the same position on both lists

        • **Lists may or may not be the same length**

      • Output Example:

Enter as many integers > 0 as you would like for the first list

followed by the value -1.


The numbers are: 1 4 5 6 -1

Enter as many integers > 0 as you would like for the second list

followed by the value -1.


The numbers are: 1 3 5 8 -1

Please enter the problem you want to attempt: 3


Numbers in same position for both lists: 5 1