I have a simple linked list:
struct element {
struct element *next;
int start;
};
struct list {
struct element *head;
struct element *tail;
};
I would not like to make a function that removes the element with the
smallest start value.
If I have three elements in my list with the following start values:
12->5->14, the list should after the remove operation look like this:
12->14
I was thinking that I would run through all the elements in the list
and store their start value in an array:
struct element *find = list.head;
while(find != 0)
{
// store the value in an array
// jump to the next element
find = find->next;
}
I would now search through this array and return the index of the
smallest value. This value +1 is the number of times I need to travel
the head of the lists next pointer to find the smallest element in the
list. I would then have another procedure to return this element and
fix the list.
The above method seems a bit messy, is there a more optimal solution to
remove a value from a linked list with a smallest key??