| Article Index |
|---|
| Merge lists |
| Souce Code |
| Documentation |
| Test Cases & Compatibility |
| All Pages |
Page 1 of 4
MERGE LISTS
Introduction :
The objective of this program is to merge two lists into one. Merging two lists will just insert the elements of both the lists into the new one and will not delete the duplicate elements. Consider two lists each of 2 nodes. Let l1 and l2 be the pointers pointing to the first elements of lists 1 and 2 respectively. The lists l1 and l2 are shown below.
The 'temp' pointer is made to point the l1 and is made to traverse the list till NULL is reached. As the list is traversed, the elements of list l1 are inserted in the new merge list,m using the insert() function. The lists l1 and m are shown below.

When the temp pointer reaches NULL , list m contains the elements of list l1. Now, temp is made to point l2, and is made to traverse list l2 till NULL. As the list is traversed all the elements of l2 are inserted in list m using insert().The lists l2 and m are shown below.
Finally when NULL is reached, the list m becomes

| < Prev | Next > |
|---|




