Linked list

Linked list

First --> [7][ ] --> [23] [ ] -->[ 9] [ ] --> [43] [ ] --> [ 51] [ ?]

I have to write a function recursive that gives the smallest data element back.

Typdef struct node {

unsigned data;

struct node *next;

} node

Can anybody help me?

[308 byte] By [WatchDoga] at [2007-10-1 17:39:19]
# 1
> I have to write a function recursiveWhy does it have to be recursive? It's not faster than the iterative solution and the stack requirement is proportional to the number of nodes.
.uj.a at 2007-7-11 3:57:00 > top of Java-index,Other Topics,Algorithms...
# 2

Can you write a recursive defnition in English?

The smallest element of a list is:

the first if it is smaller than the smallest of the rest of the list

otherwise, it is the smallest element of the rest of the list.

Now, what happens if the rest of the list is the empty list?

Figure that out and translate to Java... err C... and you'll be done.

RadcliffePikea at 2007-7-11 3:57:00 > top of Java-index,Other Topics,Algorithms...