Welcome to pickSourcecode.com Login | Register    
pickZy.com
 Home  | search  | games  | General  | C  | C++  | Java  | Php  | Networking  | Visual Basic  | VC++  | Win32  | MFC  | JavaScript  | Jobs  | JavaScript  | Post jobs
cpp list sample program       Share
2008-09-28 |  RatheeshTR  | Viewed: 268  |    0

#include <iostream>
#include <list>
using namespace std;


typedef list<int> intList;

typedef list<int>::iterator intListItor;


template<class T, class A>

void showList(const list<T, A>& aList);

int main()
{

//  define  a  list  of  integers  with  5  elements
intList ListA(5);

int j = 0;

for (intListItor ia = ListA.begin(); ia != ListA.end(); ++ia)
*ia = 5 * j++;

cout << "ListA" << "\n";

showList(ListA);


//  define  a  list  of  integers  with  6  elements
intList ListB(6);

j = 0;

for (intListItor ib = ListB.begin(); ib != ListB.end(); ++ib)
*ib = 100 * j++;

cout << "ListB" << "\n";

showList(ListB);


//  splice!
cout << "Splice:\n";

ListA.splice(++ListA.begin(), ListB, ++(++ListB.begin()), --ListB.end());

cout << "ListA" << "\n";

showList(ListA);

cout << "ListB" << "\n";

showList(ListB);


return 0;

}


//
//  Display  list  elements
//
template<class T, class A>

void showList(const list<T, A>& aList)
{

cout << "size() = " << aList.size() << ":\t";

for (list<T, A>::const_iterator i = aList.begin(); i != aList.end(); ++i)
cout << *i << ", ";

cout << "\n\n";

}


Comments:





Submit comment's

Type:

User Comment's:

Submitted By:
Prof: Software Engineer
Tech: C ,Cpp
Send Mail: ratheesh



Related topics
Cpp - Access a Class Member Function Without Creating a Class Object
Cpp - Writing Macro Definition
Cpp - using namespace std
Cpp - Using enum
Cpp - Pointers in C++
Cpp - How to use DLL file in the C++ Program
Cpp - creating and Linking DLL Files to C++ program
Cpp - 1) vector method and iterator (simple Example)
Cpp - 2) Sort and Binary search
Cpp - 3) Vector and Copy vector
Cpp - 4) for_each ( Vector )
Cpp - 5) List and Iterator
Cpp - 6) list and Vector example.2
Cpp - 7) example"fill, copy, list" statement
Cpp - 8) list and set

Related References
cpp - operator overloading
cpp - default arguments
cpp - c++ interview tips
cpp - virtual destructors
cpp - c++ destructors
cpp - csc interview questions
object oriented programming paradigm
elements of object oriented programming
basic concepts of oops and structure of c++ program
exception (runtime error) handling - cpp
cpp function pointers
cpp - access specifiers between base and derived classes
cpp - inautix interview questions
comparing popular programming languages

Web site contents © Copyright 2007, All rights reserved.
Help | Terms and Conditions | Privacy Policy | About Us