More Related Content
What's hot (20)
PPTX
Como crear una matriz de 3x3 con c++ con menu JoseGCordero
Viewers also liked (8)
PDF
1111 13.紅海潛水艇觀海底世界.胡加達城市自由活動溫秀嬌
More from UVM (20)
PPTX
Tiempo compartido en programaciónUVM
PPTX
Portafolio de evidencias del curso Programación AvanzadaUVM
PPTX
Eficiencia en uso tiempoUVM
PPTX
Administración de memoria arreglos dinamicosUVM
PPTX
Practica de arreglosUVM
PPTX
Otra introducción a apuntadoresUVM
PPTX
Ejemplo de solución de práctica funciones stlUVM
PPTX
Breve repaso de apuntadoresUVM
PPTX
Arreglos conceptos básicosUVM
PPTX
Resolución práctica de tipos de datosUVM
PPTX
Resumen de funcionesUVM
PPTX
Biblioteca estándar de funcionesUVM
PPTX
Aclaración de dudas 4 de septiembreUVM
PPTX
Aclaraciones varias a códigos entregados en sesión 3UVM
PPTX
Funciones definidas por el usuarioUVM
PPTX
Depuración de un programa en c++UVM
PPTX
Algunas dudas de la sesión 28 agostoUVM
PPTX
Estructura programa c++UVM
Practica 4 errores
- 1. #include <iostream>
#include <ctime>
using namespace std;
int inicial (int o[], int c);
void llenar (int b[10]);
void menu();
void mostrar(int x[10]);
void copia(int n[10], int m[10]);
void burbuja(int k[10]);
void seleccion(int k[10]);
void insercion(int k[10]);
void intercambio(int b[],int x, int y);
void quicksort(int b[],int inf, int sup);
int main(){
system("cls");
int c[10], cop[10],z;
cout << "METODOS DE ORDENAMIENTO"<<endl;
llenar(c);
menu();
cin>>z;
switch(z){
case 1:
cout<<"el ordenamiento por burbuja paso a paso es:"<<endl;
copia(c,cop);
burbuja(cop);
break;
case 2:
cout<<"el ordenamiento por seleccion paso a paso es: "<<endl;
copia(c,cop);
seleccion(cop);
break;
case 3:
cout<<"El ordenamiento por insercion paso a paso es: "<<endl;
copia(c,cop);
insercion(cop);
break;
case 4:
cout<<"El ordenamiento por Quick Sort paso a paso es: "<<endl;
copia(c,cop);
quicksort(cop,0,9);
break;
default:
cout<<"Opcion no valida"<<endl;
break;
}
system("pause");
return 0;
}
void llenar(int b[10]){
int num;
rand();
for (int i=0;i<10;i++){
num=rand()%100;
if(i>0){
for(int j=0;j<i;j++)
if(num==b[j]){
num=rand()%100;
j=-1;
}
- 2. }
b[i]=num;
}
}
void menu(){
cout<<"INGRESE SU OPCION SEGUN EL METODO DE ORDENAMIENTO DESDEADO:"<<endl;
cout<<"1 - BURBUJA"<<endl;
cout<<"2 - SELECCION"<<endl;
cout<<"3 - INSERCION"<<endl;
cout<<"4 - QUICK SORT"<<endl;
}
void mostrar(int x[]){
for(int h=0;h<10;h++)
cout<<x[h]<<"t";
cout<<endl;
}
void copia(int n[10], int m[10]){
for(int h=0;h<10;h++) m[h]=n[h];
}
void burbuja(int k[10]){
int b;
for(int x=0;x<10;x++){
for(int y=0;y<9;y++){
if(k[y]>k[y+1]){
b=k[y];
k[y]=k[y+1];
k[y+1]=b;
}
}
mostrar(k);
}
}
int inicial(int o[], int c){
int p=c;
int d=o[c];
for(int h=c;h<10;h++){
if(o[h]<d){
d=o[h];
p=h;
}
}
return p;
}
void seleccion(int k[10]){
int m,pos_m;
for(int l=0;l<9;l++){
pos_m = inicial(k,l);
if(k[l]<k[pos_m]){
m=k[l];
k[l]=k[pos_m];
k[pos_m]=m;
}
mostrar(k);
}
}
void insercion(int k[10]){
int m, pos_m;
- 3. for(int l=0;l<9;l++){
pos_m=inicial(k,l);
if(k[l]>k[pos_m]){
m=k[pos_m];
for(int g=pos_m-1;g>=1;g--){
k[g+1]=k[g];
}
k[l]=m;
}
mostrar(k);
}
}
void intercambio(int b[],int x, int y){
int temp;
temp=b[x];
b[x]=b[y];
b[y] = temp;
}
void quicksort(int b[], int inf, int sup){
int i,j,div;
i=inf;
j=sup-1;
div=b[sup];
while(i<=j){
if(b[i]>div && b[j]<div){
intercambio(b,i,j);
}else{
if(b[i]<=div) i++;
if(b[j]<=div) j--;
}
}
intercambio(b,i,sup);
mostrar(b);
if(inf<i-1)quicksort(b,inf,i-1);
if(i+1<sup)quicksort(b,i+1,sup);
}