Singly Linked List in C
From: Joe Wright (joewwright_at_earthlink.net)
Date: 10/28/03
- Next message: Floris van den Berg: "Re: GUI event model: synchronous or asynchronous?"
- Previous message: Darrell Grainger: "Re: need advice for algorithm"
- Next in thread: Calum: "Re: Singly Linked List in C"
- Reply: Calum: "Re: Singly Linked List in C"
- Reply: Ian Woods: "Re: Singly Linked List in C"
- Reply: Calum: "Re: Singly Linked List in C"
- Reply: Thad Smith: "Re: Singly Linked List in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Oct 2003 14:58:52 GMT
Given a singly linked list with a dummy head node, how would you go
about sorting the list based on the node's value? Consider:
typedef struct node {
int value;
struct node *next;
} node;
node dummy; /* value is 0 and next is NULL */
node *head = &dummy; /* the value of head will not change */
node *prev, *this; /* various pointers to keep track */
I have routines to add() to the list, fnd() a value in the list and
del() a node from the list. No problem. But how to sort it on value?
Because we go 'forward' scanning the list, for a given 'this' node we
have only one 'prev' adjacent node. I can do a bubble sort with this
information but not insertion because I can't go 'backward' up the list.
Am I missing something simple?
-- Joe Wright http://www.jw-wright.com "Everything should be made as simple as possible, but not simpler." --- Albert Einstein ---
- Next message: Floris van den Berg: "Re: GUI event model: synchronous or asynchronous?"
- Previous message: Darrell Grainger: "Re: need advice for algorithm"
- Next in thread: Calum: "Re: Singly Linked List in C"
- Reply: Calum: "Re: Singly Linked List in C"
- Reply: Ian Woods: "Re: Singly Linked List in C"
- Reply: Calum: "Re: Singly Linked List in C"
- Reply: Thad Smith: "Re: Singly Linked List in C"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|