实现一个函数,函数功能如下:
输入一个无序正整数数组,输出一个有序数组,并且如果数组中有连续的数字如1,2,3,4,7,8,12,15。则对于连续的数字只输出其第一个和最后一个:1,4,7,8,12,15.
完成函数 void ChangArr(int *pIn,int inLength,int *pOut,int outLength)
void QuickSort(int *arr,int low,int high)
{
int i=low,j=high;
int temp=arr[low];
if(i<j)
{while(i<j){
while(i<j && temp<arr[j])j--;
if(i<j){arr[i]=arr[j];i++;}
while(i<j && temp>=arr[i])i++;
if(i<j){arr[j]=arr[i];j--;}
}
arr[i] = temp;
QuickSort(arr,low,i-1);
QuickSort(arr,i+1,high);
}
}
void ChangArr(int*pIn ,int inLength,int *pOut,int outLength)
{
int *tempArr = new int[inLength];
for(int i=0;i<inLength;i++)
{
tempArr[i] = pIn[i];
}
QuickSort(tempArr,0,9);
for(int i=0;i<inLength;i++)
{
cout<<tempArr[i]<<" ";
}
cout<<endl;
int flag = 0;
int m = 0;
pOut[0] = tempArr[0];
for(int i = 1;i<inLength;i++)
{
if(tempArr[i] == (tempArr[i-1]+1))
{
flag++;
}
else
{
flag=0;
}
if(flag<2)
{
m++;
}
pOut[m]=tempArr[i];
}
for(int i=m+1;i<inLength;i++)
{
pOut[i] = -1;
}
delete []tempArr;
}