function for merging two lists

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2006
Posts: 6
Reputation: CyberLev is an unknown quantity at this point 
Solved Threads: 0
CyberLev CyberLev is offline Offline
Newbie Poster

function for merging two lists

 
0
  #1
Jul 22nd, 2006
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:

  1. /STLList - use the list container of std library
  2. #include <list>
  3. #include <string>
  4. #include <cstdio>
  5. #include <iostream>
  6. //declare three list of objects
  7. using namespace std;
  8. list <string> Anames;
  9. list <string> BastroSigns;
  10. list <string> MergedNamesSigns;
  11. int main()
  12. {
  13. // input string
  14. cout << "input data - name - input 0 to end" << endl;
  15. while (true)
  16. {
  17. string name;
  18. cin >> name;
  19. if (( name.compare("x") == 0) || (name.compare ("x") == 0))
  20. {
  21. break;
  22. }
  23. Anames.push_back (name);
  24. }
  25. // sort list
  26. Anames.sortedInsert ();
  27. //display list A
  28. cout << "output is: " << endl;
  29.  
  30. while (!Anames.empty())
  31. {
  32. // get first on list
  33. string name = Anames.front();
  34. cout << name<< endl;
  35. // remove displayed name from list
  36. Anames.pop_front();
  37. }
  38. / input string
  39. cout << "input data - astrological sign - input 0 to end" << endl;
  40. while (true)
  41. {
  42. string sign;
  43. cin >> sign;
  44. if (( sign.compare("x") == 0) || (sign.compare ("x") == 0))
  45. {
  46. break;
  47. }
  48. sign.push_back (sign);
  49. }
  50. // sort list
  51. BastroSigns.sortedInsert ();
  52. //display list B
  53. cout << "output is: " << endl;
  54.  
  55. while (!BastroSigns.empty())
  56. {
  57. // get first on list
  58. string sign = BastroSign.front();
  59. cout << sign<< endl;
  60. // remove displayed sign from list
  61. BastroSigns.pop_front();
  62. }
  63. createsortedList()
  64. {
  65.  
  66.  
  67.  
  68. }
  69.  
  70. mergelists()
  71. //someOperation
  72. //someNewlist
  73. //somepointer to someNewList
  74.  
  75.  
  76. system ("PAUSE") ;
  77. return 0;

Last edited by WolfPack; Jul 22nd, 2006 at 10:02 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: function for merging two lists

 
0
  #2
Jul 22nd, 2006
Please format your code
http://www.daniweb.com/techtalkforum...cement8-3.html

Colourful, but variable spaced and unindented - bad.
Monochrome, fixed width and indented - good.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: function for merging two lists

 
0
  #3
Jul 22nd, 2006
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.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 6
Reputation: CyberLev is an unknown quantity at this point 
Solved Threads: 0
CyberLev CyberLev is offline Offline
Newbie Poster

Re: function for merging two lists

 
0
  #4
Jul 22nd, 2006
I am sorry - I am new to this -
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 6
Reputation: CyberLev is an unknown quantity at this point 
Solved Threads: 0
CyberLev CyberLev is offline Offline
Newbie Poster

Re: function for merging two lists

 
0
  #5
Jul 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: function for merging two lists

 
0
  #6
Jul 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: function for merging two lists

 
0
  #7
Jul 23rd, 2006
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.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 6
Reputation: CyberLev is an unknown quantity at this point 
Solved Threads: 0
CyberLev CyberLev is offline Offline
Newbie Poster

Re: function for merging two lists

 
0
  #8
Jul 25th, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC