Fixed OS/C/Week5/q2opt fixed
This commit is contained in:
parent
f9ab48cea7
commit
330af1a823
5 changed files with 13 additions and 2 deletions
|
@ -12,7 +12,18 @@ int compare_strings(const void *a, const void *b) {
|
|||
int main(int argc, char *argv[]) {
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
qsort(&argv[1], argc - 1, sizeof(char *), compare_strings);
|
||||
int i, j;
|
||||
int count = argc - 1;
|
||||
char **strings = &argv[1];
|
||||
for (i = 0; i < count - 1; i++) {
|
||||
for (j = 0; j < count - i - 1; j++) {
|
||||
if (strcmp(strings[j], strings[j + 1]) > 0) {
|
||||
char *temp = strings[j];
|
||||
strings[j] = strings[j + 1];
|
||||
strings[j + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("Child Sorted:\n");
|
||||
for (int i = 1; i < argc; ++i)
|
||||
printf("%s\n", argv[i]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue