There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer audio black screen boot bsod computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
merging two singly-linked lists in C++, help!


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
Sphinx's Avatar
Computer Specs
Senior Member with 539 posts.
 
Join Date: Aug 2003
Experience: Computer Illiterate
01-Mar-2007, 08:58 PM #1
merging two singly-linked lists in C++, help!
ok I have prototype for the function.

Note<T> merge(Node<T> *h1, Node<T> *h2){
Node<T> *h3 = new Node<T>;



return h3;
}

So basically h1 and h2 are parameters that point to the head of each list.
The function has to merge the two lists into h3, in proper order. Assume that h1 and h2 point to the head of lists that are ordered already.


Node<T> is a class that has member variables of
T value;
Node *next

The function should return the point to the head of list3, the newly created merged list.
__________________
- Sphinx
mphair's Avatar
Senior Member with 146 posts.
 
Join Date: Dec 2005
Location: Huntington Beach, CA
Experience: I get by
04-Mar-2007, 10:43 PM #2
h3=h1
node<T> * p = h1
//loop through h1 till you get to end.
p->next = h2


there you go...h3 will be made of h1 then h2 following
VTfletch's Avatar
Computer Specs
Junior Member with 24 posts.
 
Join Date: Jan 2007
Location: Manassas, VA
Experience: Advanced
05-Mar-2007, 01:20 PM #3
Well that will give you list one followed by list two, but thats not what is being asked. It does have some good points though.

Here is some pseudo code for your problem tho.

LinkList H3;

if (H1 < H2)
H3.Head = H1
H1 = H1->Next
else
H3.Head = H2
H2 = H2->Next

While (lists not done)
if (H1 < H2)
H3.Next = H1
H1 = H1->Next
else
H3.Next = H2
H2 = H2->Next
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:06 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.