随笔分类 -  STL

Map
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 mapm; 9 m.insert(pair(1,"1234"));10 map::iterator ptr;11 m[2]="123";12 m.insert(map::value_type(3,"12")); //三种插入方式13 for(ptr=m.begin();ptr!=m.end();ptr++)14 {15 coutsecondsecond<<endl;... 阅读全文

posted @ 2013-07-12 16:48 张狂不年轻° 阅读(154) 评论(0) 推荐(0)

Set
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 int main() 8 { 9 sets;10 s.insert(19);11 s.insert(20);12 s.insert(22);13 s.insert(25);14 set::iterator ptr;15 for(ptr=s.begin();ptr!=s.end();++ptr)16 {17 cout::iterator,set::iterator> p;25 p=... 阅读全文

posted @ 2013-07-12 15:54 张狂不年轻° 阅读(154) 评论(0) 推荐(0)

List
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 listl; //创建一个空的list 9 l.assign(4,3); //分配值10 listL1;11 L1=l;12 cout::iterator ptr;15 for(ptr=l.begin();ptr!=l.end();++ptr)16 {17 cout());42 for(ptr=l.begin();ptr!=l.end... 阅读全文

posted @ 2013-07-12 15:18 张狂不年轻° 阅读(183) 评论(0) 推荐(0)

Priority_queue
摘要:priority_queue调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法实现,也算是堆的另外一种形式。先写一个用 STL 里面堆算法实现的与真正的STL里面的 priority_queue用法相似的priority_queue, 以加深对 priority_queue 的理解。 1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 class priority_queue 8 { 9 private:10 vector data;11... 阅读全文

posted @ 2013-07-12 14:18 张狂不年轻° 阅读(244) 评论(0) 推荐(0)

Stack
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 stacks; 9 for(int i=0;i<5;i++)10 {11 s.push(i);12 }13 cout<<s.top()<<endl;14 cout<<s.size()<<endl;15 for(int i=0;i<5;i++)16 {17 s.pop();18 }19 cout<<s.size()<<endl;2... 阅读全文

posted @ 2013-07-12 14:00 张狂不年轻° 阅读(161) 评论(0) 推荐(0)

Queue
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 queueQ; 9 cout<<Q.size()<<endl;10 for(int i=0;i<5;i++)11 {12 Q.push(i);13 }14 cout<<Q.front()<<endl;15 cout<<Q.back()<<endl;16 cout<<Q.empty()<<endl;17 for(int i=0;i<5;i 阅读全文

posted @ 2013-07-12 13:56 张狂不年轻° 阅读(184) 评论(0) 推荐(0)

Deque
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 dequed; 9 for(int i=0;i::iterator ptr;14 for(ptr=d.begin();ptr!=d.end();ptr++)15 {16 coutd1;26 d1=d;27 for(ptr=d1.begin();ptr!=d1.end();ptr++)28 {29 cout<<*ptr<<" ";30 }31 ... 阅读全文

posted @ 2013-07-12 13:43 张狂不年轻° 阅读(126) 评论(0) 推荐(0)

Vector
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 vectorv; 9 for(int i=0;i::iterator ptr; //智能指针,迭代器14 for(ptr=v.begin();ptr!=v.end();ptr++)15 {16 coutv1;25 v.swap(v1); //交换两个vector中的值26 for(ptr=v1.begin();ptr!=v1.end()... 阅读全文

posted @ 2013-07-12 13:15 张狂不年轻° 阅读(189) 评论(0) 推荐(0)

String
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main() 7 { 8 string str="i love you"; 9 cout<<str<<endl;10 string::iterator ptr; //智能指针11 for(ptr=str.begin();ptr!=str.end();ptr++)12 cout<<*ptr<<"";13 cout<<endl;14 string Cstr;15 Cstr= 阅读全文

posted @ 2013-07-12 10:52 张狂不年轻° 阅读(164) 评论(0) 推荐(0)

STL实现的底层数据结构
摘要:C++ STL 的实现:1.vector 底层数据结构为数组 ,支持快速随机访问2.list 底层数据结构为双向链表,支持快速增删3.deque 底层数据结构为一个中央控制器和多个缓冲区,详细见STL源码剖析P146,支持首尾(中间不能)快速增删,也支持随机访问4.stack 底层一般用23实... 阅读全文

posted @ 2013-06-08 12:58 张狂不年轻° 阅读(151) 评论(0) 推荐(0)