⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 alg4.c

📁 随书源码.新手学习不错的代码练习代码。多多指教。
💻 C
字号:
#include <algorithm>
#include <vector>
#include <iterator>
#include <iostream.h>

/* generates:
   0 1 1 3 5 8 13 
   shifting array sequence left by 1:
   1 1 3 5 8 13 13 
   shifting vector sequence left by 2:
   1 3 5 8 13 8 13 
*/

int main()
{
	int ia[] = { 0, 1, 1, 3, 5, 8, 13 };
	vector< int, allocator > vec( ia, ia+7 );
        ostream_iterator< int >  ofile( cout, " " );
		
        cout << "original element sequence:\n";
        copy( vec.begin(), vec.end(), ofile ); cout << '\n';

	// shift left by one
	copy( ia+1, ia+7, ia );

        cout << "shifting array sequence left by 1:\n";
        copy( ia, ia+7, ofile ); cout << '\n';

	// shift left by two
	copy( vec.begin()+2, vec.end(), vec.begin() );
		
        cout << "shifting vector sequence left by 2:\n";
        copy( vec.begin(), vec.end(), ofile ); cout << '\n';

	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -