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. Advertisements

  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. Advertisements

  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. Advertisements

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. Andy Sutorius

    Sorted List Snapshot?

    Andy Sutorius, Jun 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    469
    Derek Harmon
    Jun 3, 2005
  2. =?Utf-8?B?UCBL?=

    sorted List

    =?Utf-8?B?UCBL?=, Nov 14, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,731
    Karl Seguin
    Nov 15, 2005
  3. POM
    Replies:
    8
    Views:
    850
    Silvio Bierman
    Jun 14, 2004
  4. Kushal
    Replies:
    2
    Views:
    6,441
    tom_usenet
    Jan 30, 2004
  5. Replies:
    2
    Views:
    644
    Gerard Flanagan
    Mar 22, 2006
  6. Franco Perilli

    Big problem doing sorted insertion in a list

    Franco Perilli, Jul 14, 2006, in forum: C Programming
    Replies:
    3
    Views:
    426
    Franco Perilli
    Jul 15, 2006
  7. Santiago  Romero
    Replies:
    10
    Views:
    710
    Peter Otten
    Jan 21, 2008
  8. Replies:
    1
    Views:
    884
    Harold Aptroot
    Jul 16, 2008
Loading...