How to merge two initialize and merge two linked listts


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: How to merge two initialize and merge two linked listts

  1. #1
    Greg Aniagolu Guest

    How to merge two initialize and merge two linked listts


    I am experiencing some dificulties in merging two linked lists and I
    will be happy if you can give me some tips.



  2. #2
    Paul Clapham Guest

    Re: How to merge two initialize and merge two linked listts

    Here's a rough algorithm for doing it:

    Create a new, empty, linked list to hold the result.

    Set up two variables, let's call them "left" and "right", that will be used
    to traverse the two linked lists. Make "left" refer to the first entry in
    the first list and "right" refer to the first entry in the second list.

    Repeat until "left" and "right" are both null:

    ....Decide whether the entry referred to by "left" or the entry referred to
    by "right" should go in the result list first. (Note that either of these
    can be null, which means that you must use the other one.)

    ....If "left", then add that entry at the end of the result list and move
    "left" to point to the next entry in its list. (Make it null if you go past
    the end of the list.)

    .... If "right", then add that entry at the end of the result list and move
    "right" to point to the next entry in its list. (Make it null if you go
    past the end of the list.)

    And that's it. Hope that helps.

    PC2

    Greg Aniagolu <gregsnips@yahoo.com> wrote in message
    news:3a87150c$1@news.devx.com...
    >
    > I am experiencing some dificulties in merging two linked lists and I
    > will be happy if you can give me some tips.
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center