It is requested to create a vector P that contains the position of the elements of A, so that the list is traversed in order from smallest to largest. List A of M naturals.
When generating the vector P it shows me numbers that are not the ones I want. I don't know if it would be showing me the memory address.
I first tried to do it with the for loop but changed it thinking that's what was wrong. I also tried to use pos as pointer but can't fix it.
typedef int T_vector[101];
void cargar_vector(T_vector, short *);
void generar_p(T_vector, short, T_vector);
void mostrar_vector(T_vector, short);
int main()
{
T_vector A, P;
short M;
cargar_vector(A, &M);
generar_p(A, M, P);
mostrar_vector(A, M);
mostrar_vector(P, M);
return 0;
}
void cargar_vector(T_vector A, short *M)
{
int i;
printf("Ingrese el tamaño del vector: ");
scanf("%hd", M);
for (i = 1; i <= *M; i++)
{
printf("Ingrese el elemento %d: ", i);
scanf("%d", &A[i]);
}
}
void generar_p(T_vector A, short M, T_vector P)
{ /*fijar con recorrer vector*/
int men, i, j, l, k;
short pos;
men = A[1];
j = 1;
for (i = 2; i <= M; i++)
{
if (A[i] < men)
{
men = A[i];
pos = i;
}
}
P[j] = pos;
j++;
l = 1;
k = M;
for (i = 1; i <= M; i++)
{
if (A[i] >= men && i != pos)
{
while (A[i] < A[l] && A[i] < A[k])
{
P[j] = i;
j++;
l++;
k--;
}
}
}
}
void mostrar_vector(T_vector P, short M)
{
int j;
printf("El vector es :");
for (j = 1; j <= M; j++)
{
printf("%d|", P[j]);
}
}