除了这两种 一种是暴力,一种是建新表,遍历数组,每次遍历到值假设为i,那么新建表B[i]=1,代表已经有 后续如果查看这里是1,便代表有重复 直接删除即可
#include<stdio.h>
#define MAXSIZE 1000
typedef struct a{
int data[MAXSIZE];
int length;
}List;
List A;
int quicksort(int low,int high){
int flag=A.data[low];//出错 flag=第一个元素 是Low
while(low<high){
while(A.data[high]>=flag&&low<high)
high--;
A.data[low]=A.data[high];
while(A.data[low]<=flag&&low<high)
low++;
A.data[high]=A.data[low];
}
A.data[low]=flag;
return low;//返回基准
}
void partition(int low,int high){
if(low<high){
int q=quicksort(low,high);
partition(low,q-1);
partition(q+1,high);
}
}
void Delete(){
int i=0,j=1,n=A.length;
for(i,j;j<n;j++)
if(A.data[i]!=A.data[j])
A.data[++i]=A.data[j];
A.length=i+1;
}
void output(){
printf("%d\n",A.length);
for(int i=0;i<A.length;i++)
printf("%d ",A.data[i]);
}
void create(int n){
int x=0,j=0;
for(int i=0;i<n;i++){
j=0;//注意每次输出都要重置j的值确保从头开始输出
scanf("%d",&x);
for(j;j<A.length;j++)
if(A.data[j]==x)
break;//如果数组中找到任意一个与插入的相等,则不插入
if(A.length==0||j==A.length){//判断是否是无重复遍历到了最后一个
A.length++;
A.data[j]=x;
}
}
}
int main(){
int n=0;A.length=0;
scanf("%d",&n);
//法1,在建表时就对表做修改 25min
create(n);
output();
// 法2,用时30MIN,但不合题意 先排序会与要求输出不一致
/* partition(0,n-1);
Delete();
output();
*/
}