小编use*_*463的帖子

在c中排序和删除int数组中的重复项

我正在学习C并且讨论了排序问题.我写了一个comp()函数并用于qsort对数组进行排序int.现在,对于下一个任务,我需要从数组中删除重复项.
是否可以同时排序和删除重复项?

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>    
int indexes[10] = { 0, 98, 45, 65, 45, 98, 78, 56, 65, 45 };

int comp(const void * elem1, const void * elem2) {

    int f = *((int*) elem1);
    int s = *((int*) elem2);

    if (f > s) {    
        return 1;
    }    
    if (f < s) {    
        return -1;
    }    
    return 0;
}

void printIndexArray() {    
    int i = 0;    
    for (i = …
Run Code Online (Sandbox Code Playgroud)

c arrays sorting

5
推荐指数
1
解决办法
4555
查看次数

标签 统计

arrays ×1

c ×1

sorting ×1