基本算法:
變序型隊列算法——可以改變容器中數據。
int arr[6]={1,12,3,2,1215,90};
int arr1[7];
copy(arr,arr+6,arr1);//將arr指定的範圍複製給arr1。
for (int i=0; i<7; i++)
{
cout<<arr1[i]<<' ';
}
cout<<endl;
reverse(arr, arr+6);//反轉。
for (int i=0; i<7; i++)
{
cout<<arr[i]<<' ';
}
cout<<endl;
int arr2[6]={2,5,6,9,0,-56};
swap_ranges(arr, arr+6,arr2);//交換arr與arr2的數據。
copy(arr, arr+6, ostream_iterator<int>(cout, " "));
非變序型隊列算法——處理容器內數據,但是不改變。
int a[10]={12,0,5,3,6,8,9,34,32,18};
sort(a, a+10);//將a排序。
copy(a, a+10, ostream_iterator<int>(cout," "));
cout<<endl;
int b[5]={3,5,6,8,9};
if (includes(a, a+10, b, b+5 ))//判斷數組b是否爲a的子集。
{
cout<<"a中包含b"<<endl;
}
else
cout<<"a中不包含b"<<endl;
int c[15];
merge(a, a+10, b, b+5, c);//將數組a 和b合併到c.
copy(c, c+15, ostream_iterator<int>(cout," "));
cout<<endl;