Checking if the two linked lists merge

This is a discussion on Checking if the two linked lists merge within the C Programming forums, part of the General Programming Boards category; I wanted to know how do i check if the two linked lists merge. What should be the algorithm for ...

  1. #1
    Registered User
    Join Date
    Jun 2009
    Location
    US of A
    Posts
    305

    Checking if the two linked lists merge

    I wanted to know how do i check if the two linked lists merge. What should be the algorithm for this. I can only imagine that if the two linked lists merge then they will have a Y LIKE structure with both of them having a common null termination point. Any suggestions on what approach i should take to figure that out ?

  2. #2
    Registered User jdragyn's Avatar
    Join Date
    Sep 2009
    Posts
    93
    Merge how? You need to define what you mean by merge.
    Code:
    List A  A1    A2    A3
             \     \     \
    Merged    A1 B1 A2 B2 A3 B3
                /     /     /
    List B     B1    B2    B3
    
    
    List A  A1 A2 A3
             \  \  \
    Merged    A1 A2 A3 B1 B2 B3
                      /  /  /
    List B          B1 B2 B3
    What if list A has more elements than list B? What if list A has elements that duplicate list B? It's all in how you want/need to do it.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Easy, count the number of data items in each separate list - then count the number of data items in the final, merged list.

    Look into mergesort, on Wikipedia, and search this site for it as well. There was a good thread or two on that, this year.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Buidl Library with ./configure script
    By Jardon in forum C Programming
    Replies: 6
    Last Post: 07-24-2009, 09:36 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Problems about gcc installation
    By kevin_cat in forum Linux Programming
    Replies: 4
    Last Post: 08-09-2005, 09:05 AM
  4. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  5. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21