Merge two lists. : list « List « C++

C++
1. Bitset
2. Class
3. Console
4. Data Structure
5. Data Type
6. Deque
7. Development
8. File
9. Function
10. Generic
11. Language
12. List
13. Map Multimap
14. Overload
15. Pointer
16. Queue Stack
17. Set Multiset
18. STL Algorithms Binary search
19. STL Algorithms Heap
20. STL Algorithms Helper
21. STL Algorithms Iterator
22. STL Algorithms Merge
23. STL Algorithms Min Max
24. STL Algorithms Modifying sequence operations
25. STL Algorithms Non modifying sequence operations
26. STL Algorithms Sorting
27. STL Basics
28. String
29. Valarray
30. Vector
Java
XML
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C++ » List » listScreenshots 
Merge two lists.
Merge two lists.
  
#include <iostream>
#include <list>
using namespace std;
   
int main()
{
  list<int> lst1, lst2;
  int i;
   
  for(i=0; i<10; i+=2lst1.push_back(i);
  for(i=1; i<11; i+=2lst2.push_back(i);
   
  list<int>::iterator p = lst1.begin();
  while(p != lst1.end()) {
    cout << *p << endl;
    p++;
  }
   
  p = lst2.begin();
  while(p != lst2.end()) {
    cout << *p << endl;
    p++;
  }
   
  lst1.merge(lst2);
  if(lst2.empty())
    cout << "lst2 is now empty\n";
   
  cout << "Contents of lst1 after merge:\n";
  p = lst1.begin();
  while(p != lst1.end()) {
    cout << *p << " ";
    p++;
  }
   
  return 0;
}
  
    
  
Related examples in the same category
1. Instantiating an STL List of Integers
2. Use generic list to create a list of chars
3. Use generic list to create list of strings
4. Store class objects in a listStore class objects in a list
5. Store class objects with overloaded operators in a list.
6. Use std::copy to print all elements in a list
7. Pass list to a function
8. Uses ostream_iterator and copy algorithm to output list elements
9. Add elements in a multiset to a list
10. access list
11. Comparison Algorithms
12. Add elements in a set to a list
13. Using the list as a container for double value
w__w___w___._j___a___v___a___2s__.___com___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.