n个数的冒泡排序

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_16525829/article/details/102765891
#include<bits/stdc++.h>//从大到小输出 
using namespace std;
int main()
{
	int a,b,c=0;
	int num[b];
	int x=1,z=0; 
	cout<<"请输入需要比较的数字个数"<<endl;
	cin>>b; 
	cout<<"请陆续输入数字"<<endl;
	do
	{
		cin>>num[c];
		c++;
	}
	while(c<b);
	for(int n=0;n<b;n++)
	{
		for(int i=0;i<b;i++)
		{
			if(num[i]>num[i+1])
			{
	        	a=num[i];
			    num[i]=num[i+1];
			    num[i+1]=a;
			    for(int y=0;x==1;y++)
			    {
			    	x=((num[z]<num[z+1])&&x==1);
			    	z++;
			    	if(z>b)
			    	{
			    		if(x==1)
			    		{
			    		    while(b--)
			    		    {
			    		       cout<<num[b]<<endl;
					     	}
					        return 0;
				     	}
					}
				}
			}	
		}
	}
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/qq_16525829/article/details/102765891