Lab 14
Lab 14:
In this lab, we will have additional practise on linkedlist by
solving some common problems on linkedlist.
Download the starter code and follow the instructions to complete this lab
Tasks
-----
1. Complete the function displayListLength - 1 point
Here we will find the length of a given LinkedList
- Traverse the linkedllist from the beginning.
- Count how many nodes are there on the list
- Display the length of the list
2. Complete the function displayMiddleNode - 1 point
Given a list of even length (e.g. 2,4,6,8,etc) display the middle node.
For a list of length 4 it would be node 2 (the 2nd node). For a list of length
6 it would be node 3 (the 3rd node). While there are different ways to do this,
one approach is to have 2 pointers going through the list. The "fast" pointer
advances by 2 nodes on each step, and the "slow" pointer advances by only 1 node
on each step. When the "fast" one reaches the end, the "slow" one is at the node
we want.
3. Complete the function displayNthNodeFromEnd - 1 point
Display the nth from the end node for a list of length n or greater.
E.g for the following list of length 7: [ 4, 9, 2, 5, 9, 1, 3] the 3rd
from the end would be 9, and the 4th from the end would be 5.
- Prompt the user for the value of n
- Display the nth node from the end