Velocity Reviews > Insertion to a sorted list

# Insertion to a sorted list

chai
Guest
Posts: n/a

 10-07-2005
I am trying out a program to insert an element to a sorted list(singly
linked list)without using the temporary variable.Is there a solution
for this problem?

Alexei A. Frounze
Guest
Posts: n/a

 10-07-2005
"chai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I am trying out a program to insert an element to a sorted list(singly
> linked list)without using the temporary variable.Is there a solution
> for this problem?

This group deals with standard C, not algorithms. If you have an algorithm
but have problems expressing it's in terms of C (your code isn't compiling
or working as per the algorithm), come here for the help. But if you need
the algorithm, this isn't the right group to ask for it.

Alex

Mabden
Guest
Posts: n/a

 10-07-2005
"chai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> I am trying out a program to insert an element to a sorted list(singly
> linked list)without using the temporary variable.Is there a solution
> for this problem?

Not a problem. No temporary variable is required. What did your teacher
say to make you think there was one? Maybe you could stay after class
and ask, or make a friend who can help.

--
Mabden

Dale
Guest
Posts: n/a

 10-07-2005
"chai" <(E-Mail Removed)> wrote in news:1128681085.215861.272570
>
> I am trying out a program to insert an element to a sorted list(singly
> linked list)without using the temporary variable.Is there a solution
> for this problem?

I presume you mean you don't want to walk a pointer down the list looking
for the correct spot to insert.

One way would be to write a recursive insert function. Call it with a
pointer to the list, and have it call itself with the pointer to the next
node in the list until it finds the insertion point. (Not gonna write the
code for you, junior. But it ain't that hard.)

That would be a ****ing stupid way to do it, though. A temporary pointer
requires a lot less memory and fewer CPU cycles.