-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks