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

📄 maopao.cpp

📁 学生信息管理系统
💻 CPP
字号:
/**********************************************************
冒泡排序函数
原型:void paixu_maopao(double a[],const int n,const char cflag)
      a[]为数组名,n为你要对数组中的前多少个数进行排序,或你
	  的数组有多长,设定一下cflag为排序参数,有两种选择'<'和'>'
	  号,分别代码把数组中元素从小到大排序和从大到小排序
	                          written by 天涯浪子  08.5.16
***********************************************************/
#include "iostream"
/***************************************************
写模块时的测试函数
void main()
{
	void paixu_maopao(double a[],const int n,const char cflag);
	double a[LEN];
	int i,n;
	for(i=0;i<10;i++)
		cin >>a[i];
	n = 2;
	paixu_maopao(a,n,'<');
	for(i=0;i<10;i++)
		cout <<a[i] <<"   ";
}
******************************************************/
//冒泡排序函数模块
void paixu_maopao(double a[],const int n,const char cflag)
{
	double temp;
	int i,j;
	if((cflag !='<' && cflag !='>') || n<=0)//排序参数设置有误,输出提示
		printf("error: by <paixu_maopao(double a[],const int n,const char cflag)> function. The values of the parameters setting error\n");
	if(cflag =='<')  //要求从小到大排序
	{
	for(i=0;i<n-1;i++)
		for(j=i;j<n;j++)
			if(a[i]>a[j])
			{temp = a[i];a[i] = a[j];a[j] = temp;}
	}
	else if(cflag == '>')  //要求从大到小排序
	{
      for(i=0;i<n-1;i++)
		  for(j=i;j<n;j++)
			  if(a[i]<a[j])
			   {temp = a[i];a[i] = a[j];a[j] = temp;}
	}

}

⌨️ 快捷键说明

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