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

📄 13.3.cpp

📁 这是C++的一部分练习程序!对初学者有一定的帮助作用。
💻 CPP
字号:
#include <iostream.h>
#include <string.h>
template <class T>
void bubble(T *item,int n);
void main()
{
	char s[]="hyvdfreiuy";
	bubble(s,strlen(s));
	cout<<"The sorted string is "<<s<<endl;
	double d[]={3.6,9.4,1.3,15.2,7.6,0.2};
	bubble(d,6);
	cout<<"The sorted numbers are ";
	for(int i=0;i<6;i++)
		cout<<d[i]<<"  ";
	cout<<endl;
	int a[]={3,9,8,5,2,1,7,4};
	bubble(a,8);
	cout<<"The sorted numbers are ";
	for(i=0;i<8;i++)
		cout<<a[i]<<"  ";
	cout<<endl;
}
template <class T>
void bubble(T *item,int n)
{ 
	T t;
	for(int i=1;i<n;i++)
	   for(int j=n-1;j>=i;j--)
		  if(item[j-1]>item[j])
		  {
			 t=item[j-1];
			 item[j-1]=item[j];
			 item[j]=t;
		  }
}

⌨️ 快捷键说明

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