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

📄 main.cpp

📁 用c++实现的一个关于数值排序的小程序
💻 CPP
字号:
#include<iostream>
using namespace std;

template <class T> 
void chat(T a[],int n)
{
	for(int i=0;i<n-1;i++)
	{
		if(a[i]>a[i+1])
		{
			
			//cout<<"000"<<endl;
			cout<<" No."<<i+1<<"--No."<<i+2<<" is wrong"<<endl;
			cout<<"Change No."<<i+1<<" and No."<<i+2<<endl;
			T temp;
			temp=a[i];
			a[i]=a[i+1];
			a[i+1]=temp;
			for(int j=0;j<n;j++)
			{
				cout<<a[j]<<" ";
			}
			cout<<endl;
			cout<<"*****执行递归****"<<endl;
			chat(a,n);
		}
		//return 1;
		//else
		//cout<<"111"<<endl;
		cout<<" No."<<i+1<<"--No."<<i+2<<" is right"<<endl;
	}
}



void main()
{
	int n;
	cout<<"Please enter the array's number:"<<endl;
	cin>>n;
	float *a=new float[n];
	cout<<"Please enter the array's datas:"<<endl;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	chat(a,n);

		for(int j=0;j<n;j++)
		{
			cout<<a[j]<<" ";
		}
		cout<<endl;
}

⌨️ 快捷键说明

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