From: murali@pune on
Hi,
I want to insert a node in an sorted doubly linked list of integers in
ascending order. The list should not have duplicate nodes. I need an
algorithm (assuming an object oriented language)

bye

From: Thad Smith on
murali(a)pune wrote:
> Hi,
> I want to insert a node in an sorted doubly linked list of integers in
> ascending order. The list should not have duplicate nodes. I need an
> algorithm (assuming an object oriented language)

Read a text book or tutorial on linked lists.

--
Thad
From: moi on
murali(a)pune wrote:
> Hi,
> I want to insert a node in an sorted doubly linked list of integers in
> ascending order. The list should not have duplicate nodes. I need an

Take a piece of paper. Draw a comic strip featuring your nodes.
There should be at least two pictures in the strip: before and after
insertion. See what has to be done to insert your node.

Algorithm:
1) Walk the linked list, to find the proper place for insertion.
2) If a node with the new node's value is already there, it is a
duplicate: you're done
3) Insert the new node at the given place. Use the comic strip you just
made to do the right things to the right pointers/indexes.

> algorithm (assuming an object oriented language)
>

You don't need OO to draw comic strips.

> bye
>

Succes,
AvK
From: Peter "Shaggy" Haywood on
Groovy hepcat murali(a)pune was jivin' on 23 Mar 2006 06:05:00 -0800 in
comp.programming.
doubly linked list's a cool scene! Dig it!

>I want to insert a node in an sorted doubly linked list of integers in
>ascending order. The list should not have duplicate nodes. I need an
>algorithm (assuming an object oriented language)

It's very simple. If there are no nodes in the list yet, insert the
new node at the start. Otherwise, walk the list while there are nodes
left and the current node is "greater than" the new node. If You ran
out of nodes, insert the new node at the end. Otherwise, if the
current node is "equal to" the new node, quit without inserting the
new node. Otherwise, the current node is "less than" the new node;
insert the new node before the current node.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?