1
I’m trying to make a little program to sort vector and I’m using a helper function to do this, but it’s turning me on to this error message.
/media/isaque/dados/exercicios/c/scripts/estrutura de dados com c++/busca_binaria.cpp: In function ‘void ordenar_vetor(int*)’:
/media/isaque/dados/exercicios/c/scripts/estrutura de dados com c++/busca_binaria.cpp:38:7: warning: variable ‘aux’ set but not used [-Wunused-but-set-variable]
int aux;
this is my script
#include <iostream>
#include <random>
#define TAM 15
int main()
{
void ordenar_vetor(int *vetor);
int gerar_aleatorio();
int valores[TAM];
for(int c = 0; c < TAM; c++ )
{
valores[c] = gerar_aleatorio();
}
ordenar_vetor(valores);
for(int c = 0; c < TAM; c++ )
{
std::cout << valores[c] << std::endl;
}
return 0;
}
int gerar_aleatorio()
{
std::random_device m;
std::uniform_int_distribution<int> gerar(1,100);
return gerar(m);
}
void ordenar_vetor(int *vetor)
{
int aux;
for(int c = 0; c < TAM; c++)
{
for(int i = 0; i < TAM; c++)
{
if(vetor[c] < vetor[i])
{
aux = vetor[i];
vetor[i] = vetor[c];
vetor[c] = vetor[i];
}
}
}
}
I can’t identify where I’m going wrong
our truth, lack of attention my, but now I’m with another problem, when I leave commented the call of the function "sort vector" it works normal, but when I call the function it just does nothing.
– zaque
Try moving the declaration from
ordenar_vetor
on top ofmain
. Now you’re declaring insidemain
.– Kyle A
I made a mistake. I just realized there’s a mistake in
for
loop. In the first you are usingc
and the second you’re usingi
, but in the second is increasingc
when it should increasei
.– Kyle A
our is really, thank you!!
– zaque