//{2,1,2,3,5}不重复的元素个数是3
#include <iostream>
#define N 15
using namespace std;
void Sort(int *,int size);
int main()
{
bool flag=false;//以防出现连续重复的数值
int k[N] = {1,17,1,3,3,5,7,9,11,13,15,17,3,5,9};
int count=1;
int subCou=0;
Sort(k,N);
for(int i=0;i<N;i++)
cout<<" "<<k[i];
for(int i=1;i<N;i++)
{
if(k[i]!=k[i-1])
{
count++;
flag=false;
}
else
{
if(!flag)
{
subCou++;
flag=true;
}
}
}
cout<<"总元素个数:"<<N<<endl;
cout<<"重复元素个数:"<<subCou<<endl;
cout<<"不重复元素个数:"<<count-subCou<<endl;
system("pause");
return 0;
}
void Sort(int *myArray,int size)
{
int i=0,j=0;
int temp=0;
for(i=1;i<size;i++)
for(j=0;j<size-i;j++)
{
if(myArray[j]>myArray[j+1])
{
temp=myArray[j+1];
myArray[j+1]=myArray[j];
myArray[j]=temp;
}
}
}