Lab 12

In the lab we will learn to manipulate Linkedlists

Download the starter code and follow the instructions given below

Given 

----- 

A linkedlist  1 -> 3 -> 5 -> 7 -> 99

Tasks

-----

1. Complete the function displayBiggerThanNum - 1 point

Here we will try to find the number that is stored AFTER a given number

in the list. Follow the instructions below to complete this part.

- prompt the user for a number greater than 1 and lesser than 99

- get the number from the user and store it in a variable 'n'

- Traverse through the linked list till you see 'n' 

- Print the number in the list that is stored after 'n'

2. Complete the function insertNth - 1 point

This function will insert an element after the nth element in the list.

for eg: 

for the given list (above), calling this with:

       insertNth( pHead, 6, 3);

    would insert a new node with value 6, after the 3rd node, changing the list to now be:

       1 -> 3 -> 5 -> 6 -> 7 -> 99

So, you will,

- Traverse through the list until you reach the nth position

- insert the given element (be careful with the pointer assignments)

3. (Challenge problem) - 1 point

Given a list and only a pointer to some node in the middle of the list (with elements guaranteed to be after it), write the code to delete this node.  Call this with:

       deleteNode( Node *pCurrent)

    Note that here we are NOT sending the head of the list, ONLY a pointer to the node to be delete.  Is this, in fact impossible?  (Nianzu saw this as an interview question!)  Idea: copy the next node into the current node, then delete the next node!)