c语言如何删除重复字符并排序
以下是一个示例代码,可以删除重复字符并对字符进行排序:
#include <stdio.h>
#include <string.h>
void removeDuplicatesAndSort(char* str) {
int len = strlen(str);
int index = 0;
// Remove duplicates
for (int i = 0; i < len; i++) {
int j;
for (j = 0; j < index; j++) {
if (str[i] == str[j]) {
break;
}
}
if (j == index) {
str[index++] = str[i];
}
}
// Sort characters
for (int i = 0; i < index - 1; i++) {
for (int j = i + 1; j < index; j++) {
if (str[i] > str[j]) {
char temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
str[index] = '