-3
I’m creating a code with the algorithm Bubble Sort
, but when compiling I get errors
, which are:
In function 'int main()': 16 33
[Error] cannot convert 'int*' to 'int**' for argument '1' to 'int bubbleSort(int**, int*, int*, int*)' In function 'int bubbleSort(int**, int*, int*, int*)': 23 13
[Error] invalid types 'int**[int*]' for array subscript 23 23
[Error] invalid types 'int**[int*]' for array subscript 24 16
[Error] cannot convert 'int**' to 'int*' for argument '1' to 'void troca(int*, int*)
Just follow my code:
#include <stdio.h>
#include <stdlib.h>
void troca(int *a, int *b);
int bubbleSort(int *vec[5],int *a, int *b,int *qtd);
int main(){
int vet[5] = {4,7,1,13,5};
int i, j, qtd;
printf("[");
for(int i= 0; i < 5; i++){
printf(" %d",vet[i]);
}
printf(" ]");
bubbleSort(&vet[5], &i,&j, &qtd);
}
int bubbleSort(int *vec[5],int *a, int *b, int *qtd){
for(*a = 0; *a < 5; *a++){
for(*b = *a + 1; *b <= 5; *b++){
if(*vec[a] > *vec[b]){
troca(&a,&b);
qtd++;
}
}
}
printf("[");
for(int i = 0; i < 5; i++){
printf("%d ",vec[i]);
}
printf("]");
printf("Trocas: %d",*qtd);
}
void troca(int *a, int *`insira o código aqui`b){
int aux;
aux = *a;
*a = *b;
*b = aux;
}
Always try to include the error being returned, facilitates the process to help you.
– Pedro Roweder
Its swap function is being called with the indices and not with the vector’s effective positions. Try exchange(&vec[a], &vec[b]);
– anonimo