Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Insertion to a sorted list

Reply
Thread Tools

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?

 
Reply With Quote
 
 
 
 
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


 
Reply With Quote
 
 
 
 
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


 
Reply With Quote
 
Dale
Guest
Posts: n/a
 
      10-07-2005
"chai" <(E-Mail Removed)> wrote in news:1128681085.215861.272570
@z14g2000cwz.googlegroups.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?


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Constant time insertion into a sorted list? hackerbob@gmail.com C Programming 1 07-16-2008 01:13 AM
Sorting a list depending of the indexes of another sorted list Santiago Romero Python 10 01-21-2008 03:10 PM
Big problem doing sorted insertion in a list Franco Perilli C Programming 3 07-15-2006 09:39 AM
Convert (sorted) list of dics to nested list ? shearichard@gmail.com Python 2 03-22-2006 09:34 PM
STL Data Structures, Sorted Insertion? Kushal C++ 2 01-30-2004 04:37 PM



Advertisments