📄 13.3.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 + -