PROGRAMACION IV
PRACTICA 1, 2, Y 3.
/* BACHILLERATO TEC. Nø16 */
/* 6ø SEM. GRUPO:"B" */
/* PROGRAMACION IV */
/* LUIS ALBERTO JAIME PARRA */
/* PRACTICA Nø 1 */
#include <stdio.h>
#include <conio.h>
#define numero_maximo 11
int ordenar_burbuja(int vector[]);
void imprime_vector(int vector[]);
main()
{
clrscr();
int numeros[numero_maximo];
int indice, comparaciones;
printf("PROGRAMA QUE ORDENA NUMEROS ATRAVEZ DEL METODO BURBUJA.\n");
printf("Dame Diez numeros:\n");
for (indice = 1; indice < numero_maximo; indice++)
{
printf("Numero[%d] = ",indice);
scanf("%d",&numeros[indice]);
}
comparaciones = ordenar_burbuja(numeros);
imprime_vector(numeros);
printf("El numero de comparaciones fueron %d",comparaciones);
getche();
}
int ordenar_burbuja(int vector[])
{
int indice;
int seguir;
int temp;
int comp = 0;
do
{
seguir = 0;
for (indice = 1; indice < numero_maximo; indice++)
{
comp++;
if((vector[indice] > vector[indice + 1])
&&(indice != numero_maximo - 1))
{
temp = vector[indice];
vector[indice] = vector[indice + 1];
vector[indice + 1] = temp;
seguir = 1;
}
}
} while (seguir);
return(comp);
}
void imprime_vector(int vector[])
{
int indice;
printf("\nLa ordenacion queda asi: \n");
for (indice = 1; indice < numero_maximo; indice++)
printf("Numero[%d] = %d\n", indice, vector[indice]);
getche();
}
/* BACHILLERATO TEC. Nø16 */
/* 6ø SEM. GRUPO:"B" */
/* PROGRAMACION IV */
/* LUIS ALBERTO JAIME PARRA */
/* PRACTICA Nø 1 */
#include <stdio.h>
#include <conio.h>
void ordenacion_rapida(int ent[], int a, int b, int sal[]);
void mostrar_vector(int ent[],int k);
int comparaciones = 0;
main()
{
clrscr();
int vector_ent[20] = {6, 7, 5, 8, 4, 9, 3, 0, 2, 10};
int n = 10;
int vector_sal[20];
printf("PROGRAMA QUE ORDENA LOS NUMEROS POR EL METODO DE ORDENACION RAPIDA.\n\n");
printf("Desordenado => ");
mostrar_vector(vector_ent,n);
ordenacion_rapida(vector_ent,0,n-1,vector_sal);
printf("\nOrdenado => ");
mostrar_vector(vector_sal,n);
printf("\nEl numero de comparaciones fueron %d",comparaciones);
getche();
}
void mostrar_vector(int ent[], int k)
{
int i;
for(i = 0; i < k; i++)
printf("%4d",ent[i]);
printf("\n");
}
void ordenacion_rapida(int ent[], int a, int b, int sal[])
{
int pivote, i = 0, j = 0, k = 1, z = 0;
int ent1[20], ent2[20];
int sal1[20], sal2[20];
if(b != -1)
if(a == b)
sal[0] = ent[a];
else
if(1 == (b - a))
{
if(ent[a] <= ent[b])
{
sal[0] = ent[a];
sal[1] = ent[b];
}
else
{
sal[0] = ent[b];
sal[1] = ent[a];
}
comparaciones++;
}
else
{
pivote = ent[0];
while(k <= b)
{
if(pivote > ent[k])
{
ent1[i] = ent[k];
i++;
}
else
{
ent2[j] = ent[k];
j++;
}
k++;
comparaciones++;
}
ordenacion_rapida(ent1,0,i-1,sal1);
ordenacion_rapida(ent2,0,j-1,sal2);
for(k = 0; k < i; k++)
{
sal[z] = sal1[k];
z++;
}
sal[z] = pivote;
z++;
for(k = 0; k < j; k++)
{
sal[z] = sal2[k];
z++;
}
}
}
CONCLUCIONES:
ME REVOLVI CON LOS DOS ULTIMOS Y NOMAS HICE UNO SIN SABER CUL HISE ( LOS SORT )