Problems sorting code with ShellSort

0
#include <stdio.h>

typedef struct {
 int id_submissao;
 int tempo;
 int id_equipe;
 int id_problema;
 char status;
} Linha;

void shellSort(Linha *v, int n) {
 int i = (n - 1) / 2;
  int chave, k, aux;

  while(i != 0) {
   do {
     chave = 1;
     for(k = 0; k < n; k++){
        if(v[k] > v[k + i]){
           aux = v[k];
           v[k] = v[k + i];
           v[k + i] = aux;
           chave = 0;
        }
     }
  }while(chave == 0);
      i = i / 2;
  }
}

void imprimeLinhas (Linha* vet, int N) {
int i;

for (i = 0; i < N; i++)
    printf("%d %d %c %d %d\n",
           vet[i].id_equipe,
           vet[i].id_problema,
           vet[i].status,
           vet[i].tempo,
           vet[i].id_submissao);

printf("\n");
}

int main () {

FILE* arq;
Linha vet[105];
int i;

arq = fopen("EDI-1S2018-Aula11-runs.txt", "r");

for (i = 0; !feof(arq); i++)
    fscanf(arq, "%d %d %d %d %c\n",
           &vet[i].id_submissao,
           &vet[i].tempo,
           &vet[i].id_equipe,
           &vet[i].id_problema,
           &vet[i].status);

printf("**********************************\n");
printf("**   Dados antes da ordenacao   **\n");
printf("**********************************\n");
imprimeLinhas (vet, 105);

shellSort(vet, 105);

printf("\n");
printf("**********************************\n");
printf("**    Dados apos a ordenacao    **\n");
printf("**********************************\n");
imprimeLinhas (vet, 105);

return 0;
}

    
asked by anonymous 14.05.2018 / 00:39

1 answer

0

After reading a bit about shell sort I found some problems in your code, as in most sort algorithms, examples are given with integer vectors, but note that you have a struct vector, so the comparison of v [i] > v [j], like any other comparison (==,

14.05.2018 / 01:18