Программа для реализации сортировки вставки.
Your program should take as input a text file which contains numbers to be sorted and it should output a text file containing the sorted sequence and also output at each round of insertion sort. Both input and output files should be passed as command line arguments to your program as given in Sample Run. eg. Input file (input.txt) Output file (output.txt) 23 15 45 19 20 27 31 23 15 45 19 20 27 31 15 23 45 19 20 27 31 15 23 45 19 20 27 31 15 19 23 45 20 27 31 15 19 20 23 45 27 31 15 19 20 23 27 45 31 15 19 20 23 27 31 45
----
ОШИБКА В МОЕМ КОДЕ:
Status Messages:- Program compiled successfully ... Your program is not producing any output file, not allowed ... This is mostly because your program is giving a "Segmentation Fault" for some input test case, test your program with multiple test cases, identify a test case when program gives segmentation fault, debug your program and try uploading again !
Что я уже пробовал:
#include<stdio.h> #include<stdlib.h> int main(int argc, char *argv[]) { int array[argc], c, d, t,i,j; int n=argc-1; for (i = 1; i < argc; i++) { array[i - 1] = atoi(argv[i]); } for (c = 0; c < n; c++) { printf("%d ", array[c]); } for (c = 1 ; c <= n - 1; c++) { d = c; printf("\n"); while ( d > 0 && array[d] < array[d-1]) { t = array[d]; array[d] = array[d-1]; array[d-1] = t; d--; } for (j = 0; j < n; j++) { printf("%d ", array[j]); } } return 0; }
CHill60
Вы следовали инструкциям, приведенным в сообщениях о состоянии?
Для какого тестового случая ваш код вызывает ошибку сегментации?
[no name]
отладьте свою программу и попробуйте загрузить ее снова