Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65747
  • 博文数量: 42
  • 博客积分: 1730
  • 博客等级: 上尉
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-02 13:06
文章分类

全部博文(42)

文章存档

2011年(1)

2009年(41)

我的朋友

分类: C/C++

2009-11-12 11:46:53

// PartitionCopy.cpp : Defines the entry point for the console application.

//

//区间成员函数与单元素

#include "stdafx.h"
#include <time.h>
#include <iostream>
#include <vector>
using namespace std;

const int SIZE = 100000;
int data[SIZE];

int _tmain(int argc, _TCHAR* argv[])
{

    vector<int> v;
    clock_t start1,end1;
    clock_t start2,end2;

    start1 = clock();
    v.insert(v.begin(), data, data+SIZE);
    end1 = clock();
    cout<<"time1 : "<<end1-start1<<endl;

    start2 = clock();
    vector<int>::iterator loc(v.begin());
    for (int i=0; i<SIZE; i++)
    {
        loc = v.insert(loc, data[i]);
        loc++;
    }
    end2 = clock();
    cout<<"time2 : "<<end2-start2<<endl;

    return 0;
}

/*
time1 : 0
time2 : 7328
请按任意键继续. . .
*/

 

支持区间成员函数:
1:construct(InputIterator begin,  // 区间的起点
   InputIterator end);  // 区间的终点

2:insert(iterator position,   // 区间插入的位置
   InputIterator begin,  // 插入区间的起点
   InputIterator end);  // 插入区间的终点

3:erase(iterator begin, iterator end);

4:assign(InputIterator begin, InputIterator end);

阅读(404) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~