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
typedef list<int>::iterator intListItor; cpp sample       Share
2008-09-28 |  RatheeshTR  | Viewed: 884  |    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);


//  remove  an  element  from  ListA
ListA.remove(5);

cout << "5 removed from ListA:\n";

showList(ListA);


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

j = 10;

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

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

showList(ListB);


//  splice  ListA  &  ListB  and  add  an  element  10  at  the  beginning  of  ListA
cout << "splice ListA & ListB and add 10 to the beginning:\n";

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

ListA.push_front(10);


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

showList(ListA);


//  sort  ListA  first
ListA.sort();
//  so  that  elements  with  same  value  will  group  together
cout << "ListA sorted:\n";

showList(ListA);


//  remove  duplicates  from  ListA
ListA.unique();

cout << "Duplicates in ListA removed:\n";

showList(ListA);


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
Tech: C ,Cpp
Send Mail: malathi.v



Related topics
Stack Implementation
cpp stack example

General Topics
qtp : vbscript to create a file
qtp data tables
qtp page checkpoint
qtp interview questions
great art
difference between application server and webserver
tips to protect your computer against virus
elemets of a defect report

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