Re: help with linked lists

Discussion in 'C++' started by Barry Schwarz, May 23, 2004.

  1. On Wed, 19 May 2004 07:11:26 GMT, "stoj" <> wrote:

    >Hi all
    >I have just started to learn about linked lists and how to use them. I was
    >wondering how will I go about in inserting and deleting in the middle linked
    >list
    >


    You set the pointer in your new element to the value of the pointer in
    the existing element which the new element is to follow. Then you set
    the pointer in the existing element to the address of the new element.


    <<Remove the del for email>>

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    Barry Schwarz, May 23, 2004
    #1
    1. Advertising

  2. "Barry Schwarz" <> wrote in message
    news:c8o3nu$daa$0@216.39.134.16...
    > On Wed, 19 May 2004 07:11:26 GMT, "stoj" <> wrote:
    >
    > >Hi all
    > >I have just started to learn about linked lists and how to use them. I

    was
    > >wondering how will I go about in inserting and deleting in the middle

    linked
    > >list
    > >

    >
    > You set the pointer in your new element to the value of the pointer in
    > the existing element which the new element is to follow. Then you set
    > the pointer in the existing element to the address of the new element.
    >
    >


    I personally don't like singly-linked lists. Doubly-linked lists allow you
    for much faster processing if you ever want to go backwards in the linked
    list. However the concept is the same. Set the element before's pointer to
    the next one to the new one, set the element after's pointer to the previous
    one to the new one, and set the new element's pointers to the previous and
    next one.

    > <<Remove the del for email>>


    Just trying to help get rid of some spam for you: I don't see a "del" in
    your e-mail...

    -- Matt


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    Matthew Del Buono, May 24, 2004
    #2
    1. Advertising

  3. Barry Schwarz

    Tom Hyer Guest

    "Matthew Del Buono" <> wrote in message news:<ea1sc.42774$Lm3.17411@lakeread04>...
    >
    > I personally don't like singly-linked lists. Doubly-linked lists allow you
    > for much faster processing if you ever want to go backwards in the linked
    > list. However the concept is the same. Set the element before's pointer to
    > the next one to the new one, set the element after's pointer to the previous
    > one to the new one, and set the new element's pointers to the previous and
    > next one.
    >


    Yes, when you look at lists as containers of unshared data, you
    come immediately to that conclusion. One great strength of
    singly-linked lists, which this view overlooks, is that you can "cons"
    a shared ending onto many different beginnings. (Then, if you're
    writing LISP, you can call a library function which rearranges
    representations you didn't realize were shared, but that's another
    story.)

    -- Tom Hyer

    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]
    Tom Hyer, May 24, 2004
    #3
    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. Chris Ritchey
    Replies:
    7
    Views:
    475
    emerth
    Jul 10, 2003
  2. Chris Ritchey

    Generating a char* from a linked list of linked lists

    Chris Ritchey, Jul 9, 2003, in forum: C Programming
    Replies:
    7
    Views:
    462
    emerth
    Jul 10, 2003
  3. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    397
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  4. fool
    Replies:
    14
    Views:
    500
    Barry Schwarz
    Jul 3, 2006
  5. jawdoc
    Replies:
    9
    Views:
    747
    Chris Thomasson
    Mar 10, 2008
Loading...

Share This Page