我正在试着做一个函数来获取'argv',并用冒泡排序对它进行排序。由于某种原因,冒泡排序不起作用,我找不到问题。用字符串进行泡泡排序
void order(int howmany, char** strings)
{
int i = 0;
char* temp = (char*)malloc(sizeof(char)*20);
for (i = 1; i < howmany-1; i++)
{
if (strcmp(strings[i], strings[i + 1]) > 0)
{
strcpy(temp, strings[i]);
strcpy(strings[i], strings[i+1]);
strcpy(strings[i + 1], temp);
}
else if (strcmp(strings[i], strings[i + 1]) < 0)
{
continue;
}
else
{
continue;
}
}
}
你应该做一些调试。 –
问题是使用冒泡排序的逻辑,http://stackoverflow.com/questions/16636890/sorting-strings-with-bubble-sort-algorithm –
在就地修改命令行参数是一个坏主意。首先制作它们的副本,然后对其进行分类。 – Lundin