Insertion to a sorted list

Discussion in 'C Programming' started by chai, Oct 7, 2005.

  1. chai

    chai Guest

    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?
     
    chai, Oct 7, 2005
    #1
    1. Advertising

  2. "chai" <> wrote in message
    news:...
    > 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
     
    Alexei A. Frounze, Oct 7, 2005
    #2
    1. Advertising

  3. chai

    Mabden Guest

    "chai" <> wrote in message
    news:...
    > 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
     
    Mabden, Oct 7, 2005
    #3
  4. chai

    Dale Guest

    "chai" <> 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 fucking stupid way to do it, though. A temporary pointer
    requires a lot less memory and fewer CPU cycles.
     
    Dale, Oct 7, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kushal
    Replies:
    2
    Views:
    6,220
    tom_usenet
    Jan 30, 2004
  2. Replies:
    2
    Views:
    507
    Gerard Flanagan
    Mar 22, 2006
  3. Franco Perilli

    Big problem doing sorted insertion in a list

    Franco Perilli, Jul 14, 2006, in forum: C Programming
    Replies:
    3
    Views:
    310
    Franco Perilli
    Jul 15, 2006
  4. Santiago  Romero
    Replies:
    10
    Views:
    530
    Peter Otten
    Jan 21, 2008
  5. Replies:
    1
    Views:
    697
    Harold Aptroot
    Jul 16, 2008
Loading...

Share This Page