write an algorithm that accepts a linked list, traverses it and retrurns the data in the node with the minimum key value. ( data is the key ; so we should have to compare the data of each node until we find the minimum value)
My start ;
algorithm minimum (val pList <head pointer>)
This algorithm accepts a link list , traverses it and returns the data in the node with the minimum key value.
Pre = pList is a valid pointer to the head of the list
Post= the data with the minimum key value has been returned or in the case of an empty list , an invalid data is returned
If (fromwhere is 0) start at first element
1 If (pList -> count is zero)
1 return ( invalid data value) checks null list
this is where I dont how to continue I can use a pWalker or a pList ->pos . one way or the other we have to keep track of where we are and where we are going , plus compare data nodes , I was going to use datakey as the variable to compare the data at each position .
dataptr = address ( pList -> pos -> data) tracks address
then some how I have to move to the next node .If data is not less then what is in datakey ignore.Go to next data node until end of list and terminate.
2 pList ->pos = pList ->head
3 dataptr = address ( pList -> pos -> data)
4 datakey < data ( pList -> pos -> data ) compares data
5 sucess = true
Now I am not sure what else to proceed with , and how to show the minimum key value . I could tell it to print it out or can I display it to the screen.
any help would be greatly appreciated .
I am using the Data Structures Pseudocode Approach in C.
Gilberg and Forouzan