冒泡排序 并去重

#include<bits/stdc++.h>
using namespace std;
int a[1000],b[1000]={
    
    -1};  


void gudu_gudusort(int n)
{
    
        int flags=1;
	for(;n>0&&flags==1;n--)
    {
    
         flags=0;
    	for(int i=0;i<n;i++)
    	{
    
    
    		if(a[i]>a[i+1])
    		{
    
    
    			flags=1;
    			swap(a[i],a[i+1]);
			}
		}
	}
}

void temp_plus(int n)
{
    
    
	for(int i=1;i<=n;i++)
	{
    
    
		if(a[i]!=a[i+1])
		{
    
    
			b[i]=a[i];
		}
		else b[i]=-1;
	}
}
void shows(int n)
{
    
    
	for(int i=1;i<=n;i++)
	if(b[i]!=-1)
	cout<<b[i]<<" ";
}
int main()
{
    
    

   int i=0,f=0;
     while(cin>>a[i])
     {
    
    
     	 i++;
     	 f++;
	 }
//	 cout<<f;
	 gudu_gudusort(f);
	 temp_plus(f);
	 shows(f);
    
    return 0;
}
  

猜你喜欢

转载自blog.csdn.net/weixin_46339668/article/details/110186483
今日推荐