I am working out a function that merges two lists and returns a pointer to a third list which contains the merged lists. Can anyone help? Here is what I have thus far:

/STLList - use the list container of std library
#include <list>
#include <string>
#include <cstdio>
#include <iostream>
//declare three list of objects 
using namespace std;
list <string> Anames;
list <string> BastroSigns;
list <string> MergedNamesSigns;
int main()
{
// input string
cout << "input data - name - input 0 to end" << endl;
while (true)
{ 
string name;
cin >> name;
if (( name.compare("x") == 0) || (name.compare ("x") == 0))
{
break;
}
Anames.push_back (name);
}
// sort list
Anames.sortedInsert ();
//display list A
cout << "output is: " << endl;

while (!Anames.empty())
{
// get first on list
string name = Anames.front();
cout << name<< endl;
// remove displayed name from list
Anames.pop_front();
}
/ input string
cout << "input data - astrological sign - input 0 to end" << endl;
while (true)
{ 
string sign;
cin >> sign;
if (( sign.compare("x") == 0) || (sign.compare ("x") == 0))
{
break;
}
sign.push_back (sign);
}
// sort list
BastroSigns.sortedInsert ();
//display list B
cout << "output is: " << endl;

while (!BastroSigns.empty())
{
// get first on list
string sign = BastroSign.front();
cout << sign<< endl;
// remove displayed sign from list
BastroSigns.pop_front();
}
createsortedList()
{ 
 
 
 
}
 
mergelists()
//someOperation
//someNewlist
//somepointer to someNewList
 
 
system ("PAUSE") ;
return 0;

Recommended Answers

All 7 Replies

Haven't you even tried writing the merge function? You may have written the other parts, but that is not relevent here. Merging two lists can't be that hard. It is just a matter of connecting the tail of one list, with the head of the other list.

Please remember that when you ask a question, you must try to post only the parts that are needed for us to answer that particular question. Posting all code and expecting us to weed through that is outright rude.

Since you are using the standard list, you can use the splice method.

I am sorry - I am new to this -

Hi Wolfpack. thank you for responding. Sorry about the bad manners. I am new to this..I assure you I am a professional and polite person. The problem I am working on is basically to do the merge of two lists without using the std library. I have looked every where and I cannot find the code for the stl merge (). Is there a place I can find such things. I think this is analogous to finding the code behind operators and keywords. What are your thoughts? Can you help - I think I am being asked to re-invent the wheel..Thank you for your help.

Basically, you look at the first element of each input list, and decide which one you want first.
You then remove that from the head of whichever input list and append it to your result list.
Keep doing that until both input lists are empty.

No need to appologise. We know you are a good fellow.

The problem I am working on is basically to do the merge of two lists without using the std library.

If you are already using the standard list, what is keeping you from using the merge function?

I have looked every where and I cannot find the code for the stl merge (). Is there a place I can find such things.

Well this code is old, but you can take a look. The copyright says that it is free as long as you do not delete the disclaimer. If anybody sees any legal issues in posting this link here, notify me and I will delete it.

I think this is analogous to finding the code behind operators and keywords. What are your thoughts? Can you help - I think I am being asked to re-invent the wheel.

Unless you are writing this code for academic purposes, I'd advice you to use the reliable standard library.

Thank you Wolfpack. Yes it is for academic purposes. I am an intellectual property and computer law attorney and my opinion is that you have complied with the disclaimer..thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.