-1
I’m trying to create the basic structure for a program that uses Bubble Sort. However, when testing its basic structure, I see that the final vector is not being returned correctly.
#include <stdio.h>
#define TAMANHO 5
int main() {
int vetor[TAMANHO-1],n1,n2,ctr,ctrInt;
for(ctr=0;ctr<TAMANHO;ctr++) scanf("%d",&vetor[ctr]);
for(ctr=0;ctr<TAMANHO;ctr++){
for(ctrInt=0;ctrInt<TAMANHO-ctr-1;ctrInt++){
n1=vetor[ctrInt];
n2=vetor[ctrInt+1];
if(n1>n2){
vetor[ctrInt]=n2;
vetor[ctrInt+1]=n1;
}
}
}
for(ctr=0;ctr<TAMANHO;ctr++) printf("%d",vetor[ctr]);
return 0;
}
And the exchange of values is not right either. To exchange two values Voce needs a temporary variable.
– Isac