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 - 6) list and Vector example.2       Share
2008-11-03 |  RatheeshTR  | Viewed: 562  |    0

#include <algorithm>
#include <list>
#include <iostream.h>
        

class Even {

public:

   bool operator()( 
int val )
        { return val%2 ? false : true; }

};

        

int main()
{

   
int ia[] = {0,1,1,2,3,5,8,13,21,34};
    list< int,allocator > ilist( ia, ia+10 );

/*
 *  unsupported  in  current  implementation
 *****************************************************
       typedef      iterator_traits<InputIterator>::distance_type    distance_type;
                             distance_type  ia_count,  list_count;
       
       //  count  even  elements:  4
        ia_count  =  count_if(  &ia[0],  &ia[10],  Even()  );
       list_count  =  count_if(  ilist.begin(),  ilist_end(),
                                                     bind2nd(less<int>(),10)  );
 ******************************************************
 */

    
int ia_count = 0;
    count_
if( &ia[0], &ia[10], Even(), ia_count );
   

    
//  generates:
    
//      count_if():  there  are  4  elements  that  are  even.
   

    cout << "count_
if(): there are " << ia_count < " elements that are even.\n";
   

    
int list_count = 0;
    count_
if( ilist.begin(), ilist.end(), bind2nd(less<int>(),10), list_count );
   

   
//  generates:
   
//  count_if():  there  are  7  elements  that  are  less  than  10.
   

  cout << "count_
if(): there are " << list_count
          << " elements that are less than 10.\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 - regular expression example
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

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