Program The Future !

Program The Future !
 
 

常用链接

  • 我的随笔
  • 我的评论
  • 我参与的随笔

留言簿(1)

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类

  • acm/icpc(2) (rss)
  • 生活 (rss)
  • 学习 (rss)

随笔档案

  • 2007年5月 (5)

文章档案

  • 2007年8月 (1)

收藏夹

  • myfriends (rss)

搜索

  •  

最新评论

阅读排行榜

  • 1. 转 STL算法学习 (891)
  • 2. STL通用算法:1、非修正序列算法(347)
  • 3. 第二类通用算法---修正序列算法(272)
  • 4. 并查集(223)
  • 5. STl学习(192)

评论排行榜

  • 1. 并查集(0)
  • 2. STl学习(0)
  • 3. STL通用算法:1、非修正序列算法(0)
  • 4. 第二类通用算法---修正序列算法(0)
  • 5. 转 STL算法学习 (0)

Powered by: 博客园
模板提供:沪江博客
C++博客 | 首页 | 发新随笔 | 发新文章 | 联系 | 聚合 | 管理

2007年5月22日

转 STL算法学习
     摘要:   阅读全文
posted @ 2007-05-22 22:16 y05zh 阅读(891) | 评论 (0) | 编辑 收藏
 

2007年5月21日

第二类通用算法---修正序列算法

copy

template<class InIt, class OutIt>
        OutIt copy(InIt first, InIt last, OutIt x);

copy_backward

 
template<class BidIt1, class BidIt2>
       BidIt2 copy_backward(BidIt1 first, BidIt1 last, BidIt2 x);
Function:         fill(first,last,val)
Description:        把val的值赋给first,last中所有的元素
Parameter:        起始位置和要赋的值

template<class FwdIt, class Gen>
       void generate(FwdIt first, FwdIt last, Gen g);
 
Function:      partition(first,last,pred)
Description:        在指示器first,last中经过谓词的判断后一分为二
Parameter:        起始位置和谓词
Function:      random_shuffle(first,last)
Description:        在指示器first,last中随机排列元素
Parameter:        起始位置

copy

template<class InIt, class OutIt>
OutIt copy(InIt first, InIt last, OutIt x);

copy_backward

template<class BidIt1, class BidIt2>
BidIt2 copy_backward(BidIt1 first, BidIt1 last, BidIt2 x);
 
Function:      fill(first,last,val)
Description:     把val的值赋给first,last中所有的元素
Parameter:     起始位置和要赋的值

template<class FwdIt, class Gen>
void generate(FwdIt first, FwdIt last, Gen g);
 
Function:      partition(first,last,pred)
Description:     在指示器first,last中经过谓词的判断后一分为二
Parameter:     起始位置和谓词
Function:      random_shuffle(first,last)
 Description:     在指示器first,last中随机排列元素
 Parameter:     起始位置

remove

template<class FwdIt, class T>
FwdIt remove(FwdIt first, FwdIt last, const T& val);

replace

template<caass FwdIt, class T>
void replace(FwdIt first, FwdIt last,
const T& vold, const T& vnew);
reverse

template<class BidIt>
void reverse(BidIt first, BidIt last);
 
 
Function:      rotate(first,middle,last)
 Description:     把从middle到last的元素旋转到first范围处
 Parameter:     起始位置和开始旋转位置
 

swap

template<class T>
void swap(T& x, T& y);
 

swap_ranges

template<class FwdIt1, class FwdIt2>
FwdIt2 swap_ranges(FwdIt1 first, FwdIt1 last, FwdIt2 x);
 

transform

template<class InIt, class OutIt, class Unop>
OutIt transform(InIt first, InIt last, OutIt x, Unop uop);//还没弄懂!
 
 

unique

template<class FwdIt>
FwdIt unique(FwdIt first, FwdIt last);

 
 

 



 

posted @ 2007-05-21 00:35 y05zh 阅读(272) | 评论 (0) | 编辑 收藏
 
STL通用算法:1、非修正序列算法

STL通用算法:                     Description:
1、非修正序列算法             不对其所作用的容器进行修改
2、修正序列算法               对其所作用的容器进行修改
3、排序算法                   对容器的内容进行不同方式的排序
4、数值算法                   对容器的内容进行数值计算

Function:    adjacent_find(first,last)
Description: 搜索重复对
Parameter:       搜索时的起始位置
Return:        返回在该区间第一个重复的对.

count(first,last,val);

equal

template<class InIt1, class InIt2>
      bool equal(InIt1 first, InIt1 last, InIt2 x);
template<class InIt1, class InIt2, class Pred>
      bool equal(InIt1 first, InIt1 last, InIt2 x, Pred pr);
 
for_each(first,last,func)
     对first,last范围内每个元素执行func定义的函数
first,last要执行元素的范围,func自己定义的函数

第一类--非修正序列算法还有其他函数

equal(first,last,first2)
find(first,last,val)
find_end(first,last,first2,last2)
find_first(first,last,first2,last2)
mismatch(first,last,first2)
search(first,last,first2,last2)

posted @ 2007-05-21 00:32 y05zh 阅读(347) | 评论 (0) | 编辑 收藏
 
STl学习

谓词是stl用来确定容器中元素信息的一种函数。用户可以自己定义!

stl是一个容器类模板库和算法库!

序列容器(sequence container ):向量(vector)链表(list),双端队列(deque);

容器适配器:堆栈(stack),队列(queue),优先队列(priorty_queue);

关联容器(assocjative container ):集合(set),多重集合(multiset),映射(map),

多重映射(multimap);

迭代器(iterator);

posted @ 2007-05-21 00:31 y05zh 阅读(192) | 评论 (0) | 编辑 收藏
 
并查集

主要有三个函数:

void UFset()//初始化
{
for(int i=0;i<N;i++)
{
   parent[i]=-1;
}
}


int find(int x)//返回X节点所属集合的根节点
{
for(int i=x;parent[i]>=0;i=parent[i]);
while(i!=x)//优化方案--压缩路径
{
   int tmp=parent[x];
   parent[x]=i;
   x=tmp;
}
return i;
}


void Union(int R1,int R2)//将两个不同集合的元/////////素进行合并,使两个集合中任两个元素都连通

{
int tmp=parent[R1]+parent[R2];
if(parent[R1]>parent[R2])//优化方案――加权法则

{
   parent[R1]=R2;
   parent[R2]=tmp;
}
else
{
   parent[R2]=R1;
   parent[R1]=tmp;
}
}

posted @ 2007-05-21 00:21 y05zh 阅读(223) | 评论 (0) | 编辑 收藏
 
仅列出标题