map && multimap

//the usage of multimap is as same as the map #include<iostream>#include<map>#include<string>using namespace std;typedef map<int,string> MAP_INT_STR;typedef pair<int,string> PAIR_INT_STR;template<typename ITERATOR>void print_map_item(ITERATOR it){ cout<<(*it).first<<","<<(*it).second<<endl;}i...
STL | 2008-08-17 14:34 | 阅读 4377 次 | 评论 0 条

construct map &amp;&amp; multimap

//map's constructor,and the multimap's constructor is as some as the map's#include<iostream>#include<map>#include<iterator>using namespace std;int main(void){ typedef pair<int,int> Int_Pair; map<int,int>::iterator Iter; map<int,int> map1; //empty map map<int,int,less<int> > map2; ...
STL | 2008-08-17 14:30 | 阅读 4462 次 | 评论 0 条

Multiset

//multiset #include<iostream>#include<set>#include<algorithm>using namespace std;int main(void){ multiset<int> mul1; //default constructor int arr[] = {0,0,1,1,2,3,4,5}; multiset<int> mul2(arr,arr+8); multiset<int> mul3(mul2); multiset<int>::iterator Iter; multiset<int>::...
STL | 2008-08-17 14:28 | 阅读 4112 次 | 评论 0 条

Set

#include<iostream>#include<set>using namespace std;int main(void){ set<int> s1; int arr[] = {0,0,0,0,1,1,2,3}; set<int> s2(arr,arr+8); //construct from a range set<int> s3(s2); set<int>::iterator Iter; set<int>::reverse_iterator RevIter; if (s1.empty()) cout<<"set s1 is em...
STL | 2008-08-17 14:26 | 阅读 4043 次 | 评论 0 条

construct Set &amp;&amp; Multiset

//set//multiset's constructor is as same as the set#include<iostream>#include<set>using namespace std;int main(void){ set<int>::iterator Iter; //set<int>::iterator s1_Iter,s2_Iter,s3_Iter,s4_Iter,s5_Iter,s6_Iter; set<int> s0; //create an empty set s0 of key type integer set<int,less...
STL | 2008-08-17 14:24 | 阅读 5022 次 | 评论 0 条

List

#include<iostream>#include<list>#include<algorithm>using namespace std;int main(void){ list<int> c1,c2,c3,c4; list<int>::iterator c1_Iter,c2_Iter,c3_Iter,w_Iter,f_Iter,l_Iter; c1.push_back(10),c1.push_back(10), c1.push_back(20), c1.push_back(30); c2.push_back('u'), c2.push_back('a'), ...
STL | 2008-08-17 14:21 | 阅读 3916 次 | 评论 0 条

Deque

//Deque(dounle_ended queues] #include<iostream>#include<deque>#include<string>#include<iterator>#include<algorithm>using namespace std;int main(void){ deque<int> c1; //defauilt constructor deque<int> c2(10,4); //create a deque with 10 copies of 4 deque<int> c3(c2); ...
STL | 2008-08-17 14:16 | 阅读 3625 次 | 评论 0 条

Vector

#include<iostream>#include<vector>#include<algorithm>#include<iterator>using namespace std;void Pause(){ char c; cout<<"\npress return to continue: "; cin.get(c); cout<<endl;}int main(){ vector<int> v(10,0); ostream_iterator<int> out(cout," "); //定义一个输出迭代器 copy(v.begin(),v.e...
STL | 2008-08-17 14:12 | 阅读 3484 次 | 评论 0 条

声明一下,我这里贴代码用的高亮软件是雨中飞燕之作.

本代码使用的高亮软件是雨中飞燕之作: "HighlightCodeV3.0 software by yzfy(雨中飞燕) http://yzfy.org **" 大家看代码时请先点击右边的"关闭侧边栏",这样看代码会好看一点...
默认分类 | 2008-08-02 23:13 | 阅读 4428 次 | 评论 0 条

我写的HashTable

//HashTable.h #include<iostream>const int defaultsize = 100;enum KindOfStatus{ Active,Empty,Deleted};template<class E,class K>struct ChainNode{ E data; ChainNode<E,K> *link;};template<class E,class K>class HashTable{private: int divisor; //除数,必须是质数 i...

排序(1)

#include<iostream>#include<ctime>#define Swap(i,j) {int s = (i); (i) = (j); (j) = s;}const int MAXSIZE = 30;int array[MAXSIZE];/*直接插入排序基本思想:当插入第I个元素时,前面的V[0],V[1]....V[I-1]已经排好序,这时用V[I]的排序码与V[I-1],V[I-2]....的排序码进行比较,找到插入位置即将V[I]插入,原来位置上的元素向后移.*/void InsertSort(int (&amp;array)[MAXSIZE],const int ...

稀疏矩阵转置

/* -------------存储结构-三元组----------------- #define MAXSIZE 10000 /*非0元素个数最大值10000*/ typedef struct{ int i,j; /*非0元素的行、列下标*/ ElemType e; /*非0元素值*/ }Triple; typedef struct{ /*稀疏距阵存储结构*/ Triple data[MAXSIZE+1];/...

写一个创建稀疏矩阵相应三元组的算法。

创建稀疏矩阵相应三元组的算法如下所示: #define MAXSIZE 1000 /*假设非零元个数的最大值是1000*/ typedef struct { int i, j; elemtype v; }triple; typedef struct { triple data[MAXSIZE+1]; /*data[0]用于存放稀疏矩阵行,列和非零元个数*/ int mu, nu, tu; /*稀疏矩阵行、列和非零元的个数*/ } spmatrix; spmatrix a; void CreatTripleTable (int array_a[M][N],spm...

“魔方阵”算法&amp;稀疏矩阵三元组算法

用二维数组实现"魔方阵"的打印,所谓“魔方阵”是指满足每一行,每一列和对角线上的元素之和均相等的方阵。如: 8 1 63 5 74 9 2 就是一个三阶的魔方阵。现在要求编程实现任意输入一个自然数n,打印出相应的n阶魔方阵。 参考答案: 打印“魔方阵”算法如下所示: void MagicMatrix( ) { int a[16][16],i,j,k,p,m,n; p=1; while(p==1) /*输入1~15的奇数*/ { printf("Please input n(n=1~15)\n"); scanf("%d",&amp;...
浏览56089次
最新评论