// If next is NULL we are on the last entry in the list (or we've broken our list!)
while(temp->next!=NULL)
{
temp=temp->next;// Change our temp pointer from the current one to temp->next - "moving" us on to the next node
}
temp->next=new_node;
return;
}
/* Exercise Tasks
1. Write a function int ListLength(node *start) which traverses the list, counts the number of nodes and returns that count.
2. Write a function void AddNode(node **ptr_to_start, int value)
This function should insert a node in to a place in the list so that the list is stored
in ascending order of value. e.g. 3,7,9,122 etc
If the list is empty it should add a new node at the start of the list
If the list is not empty it should
- traverse the list until it finds a value greater than value and insert a new node before the node with the greater value
- if it reaches the end of the list without finding a greater value,
it should add a new node to the end of the list
3. Test the function from 1 with these values added in this order 5,6,2,7,4 and make sure you
get the correct output with PrintLinkedList
4. Write a function void SortList(node **ptr_to_start) which takes an unsorted list and rearranges it
in to a sorted list
The function should implement a bubble sort and swap the values within the nodes around
Bubble Sort
In a bubble sort we travese our way through a list from the start and test each node with the one after it. If the node value is greater than the one after it we swap the two nodes in the list.
Once we've made it to the end of the list we return to the start and repeat the process.
When he have done this a number of times equal to the length of the list minus 1 we can be sure we have sorted our list.
Use the following function calls to set up the list for testing