is there a good guide someone can point me to?

I'm trying to learn from my lecture notes, but they aren't very descriptive.

my books don't mention them neither.

Printable View

- 03-29-2009ktran03learning how to do sorted linked lists
is there a good guide someone can point me to?

I'm trying to learn from my lecture notes, but they aren't very descriptive.

my books don't mention them neither. - 03-29-2009MK27
You should be able to google "C linked list tutorial" and find a ton. Sorting may or may not be included; sometimes sorting is discussed in terms of an algorithm in pseudo code rather than a particular language (there are about half a dozen common algorithms).

Sorting is easiest with integers, so give your nodes some kind of number to work with

Code:`typedef struct _node {`

char name[32];

int number;

struct _node *next;

} node;

- bubblesort (easiest)
- insertion sort
- selection sort
- merge sort
- quick sort (trickiest)

Write each sort as a single function that calls a separate simple comparison routine (then you can swap a different routine in later for dealing with strings). The comparison for ints can be this simple:

Code:`int compare_numbers (int a, int b) {`

if (a==b) return 0;

if (a>b) return 2;

else return 1;

}

- 03-29-2009creeping death
how about

Linked list - Wikipedia, the free encyclopedia

while inserting an element into the link list, check where it would belong according to the element's magnitude,compared to the rest of the elements already present in the LL

then you got yourself a sorted linked list.