SlideShare a Scribd company logo
#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;
                        }
}
           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;
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);
}

More Related Content

What's hot (20)

TXT
Zadatak
Zeljko Lukic
 
DOCX
Programacion
saraguaman15465
 
PPTX
Como crear una matriz de 3x3 con c++ con menu
JoseGCordero
 
PDF
Bcsl 033 data and file structures lab s1-2
Dr. Loganathan R
 
DOCX
Passato
Paulina Paz
 
DOCX
Fcfs Cpu Scheduling With Gantt Chart
One97 Communications Limited
 
TXT
Los fantastico
Brenda Jazmin
 
PPTX
Kelompok 2.6
fiqriany1300018072
 
DOCX
Rafael torrest
rfltorres
 
TXT
C Program : Sorting : Bubble,
Meita Jayani
 
DOCX
Luis cuñas programacion
luisitofranklin
 
DOC
Absolute Loader
ksanthosh
 
DOCX
c ++ informe Nº5 ucsm
Isaac Aquino
 
PDF
Kruskal algorithm
Nguyễn Công Hoàng
 
PPTX
Kelompok 2.6
1300018075
 
PPTX
Kasus 3.3 akar
istwiariindri
 
PDF
Sujet bac info 2012 g1, g2 et g3 avec correction
borhen boukthir
 
KEY
python-geohex
遼 会田
 
PPTX
Kelompok 2.5
1300018075
 
PDF
Corridas
Xavi Devaluado
 
Zadatak
Zeljko Lukic
 
Programacion
saraguaman15465
 
Como crear una matriz de 3x3 con c++ con menu
JoseGCordero
 
Bcsl 033 data and file structures lab s1-2
Dr. Loganathan R
 
Passato
Paulina Paz
 
Fcfs Cpu Scheduling With Gantt Chart
One97 Communications Limited
 
Los fantastico
Brenda Jazmin
 
Kelompok 2.6
fiqriany1300018072
 
Rafael torrest
rfltorres
 
C Program : Sorting : Bubble,
Meita Jayani
 
Luis cuñas programacion
luisitofranklin
 
Absolute Loader
ksanthosh
 
c ++ informe Nº5 ucsm
Isaac Aquino
 
Kruskal algorithm
Nguyễn Công Hoàng
 
Kelompok 2.6
1300018075
 
Kasus 3.3 akar
istwiariindri
 
Sujet bac info 2012 g1, g2 et g3 avec correction
borhen boukthir
 
python-geohex
遼 会田
 
Kelompok 2.5
1300018075
 
Corridas
Xavi Devaluado
 

Viewers also liked (8)

DOC
Sin título 2
chhiikiiss
 
PPTX
Play station 4
carlosoliermontenegrosj
 
PDF
1111 13.紅海潛水艇觀海底世界.胡加達城市自由活動
溫秀嬌
 
PPT
Slidecast FABIAN HERNANDEZ MATIZ
fabianhernandez1030
 
PPS
Chorei ao ver isso
Leide Barbosa
 
PPTX
JSTOR & Aaron Swartz
Zoe Fisher
 
PPT
Medicina alternativa y complementariaclases2013
cmazariegos56
 
DOCX
Actividad económica
Elizabeth Peshosha
 
Sin título 2
chhiikiiss
 
Play station 4
carlosoliermontenegrosj
 
1111 13.紅海潛水艇觀海底世界.胡加達城市自由活動
溫秀嬌
 
Slidecast FABIAN HERNANDEZ MATIZ
fabianhernandez1030
 
Chorei ao ver isso
Leide Barbosa
 
JSTOR & Aaron Swartz
Zoe Fisher
 
Medicina alternativa y complementariaclases2013
cmazariegos56
 
Actividad económica
Elizabeth Peshosha
 
Ad

More from UVM (20)

PPTX
Tiempo compartido en programación
UVM
 
PPTX
Portafolio de evidencias del curso Programación Avanzada
UVM
 
PPTX
Eficiencia en uso tiempo
UVM
 
PPTX
Administración de memoria arreglos dinamicos
UVM
 
PPTX
Practica de arreglos
UVM
 
PPTX
Otra introducción a apuntadores
UVM
 
PPTX
Ejemplo de solución de práctica funciones stl
UVM
 
PPTX
Breve repaso de apuntadores
UVM
 
PPTX
Arreglos conceptos básicos
UVM
 
PPTX
Resolución práctica de tipos de datos
UVM
 
PPTX
Resumen de funciones
UVM
 
PPTX
Biblioteca estándar de funciones
UVM
 
PPTX
Manejo de bits
UVM
 
PPTX
Aclaración de dudas 4 de septiembre
UVM
 
PPTX
Aclaraciones varias a códigos entregados en sesión 3
UVM
 
PPTX
Funciones definidas por el usuario
UVM
 
PPTX
Función main()
UVM
 
PPTX
Depuración de un programa en c++
UVM
 
PPTX
Algunas dudas de la sesión 28 agosto
UVM
 
PPTX
Estructura programa c++
UVM
 
Tiempo compartido en programación
UVM
 
Portafolio de evidencias del curso Programación Avanzada
UVM
 
Eficiencia en uso tiempo
UVM
 
Administración de memoria arreglos dinamicos
UVM
 
Practica de arreglos
UVM
 
Otra introducción a apuntadores
UVM
 
Ejemplo de solución de práctica funciones stl
UVM
 
Breve repaso de apuntadores
UVM
 
Arreglos conceptos básicos
UVM
 
Resolución práctica de tipos de datos
UVM
 
Resumen de funciones
UVM
 
Biblioteca estándar de funciones
UVM
 
Manejo de bits
UVM
 
Aclaración de dudas 4 de septiembre
UVM
 
Aclaraciones varias a códigos entregados en sesión 3
UVM
 
Funciones definidas por el usuario
UVM
 
Función main()
UVM
 
Depuración de un programa en c++
UVM
 
Algunas dudas de la sesión 28 agosto
UVM
 
Estructura programa c++
UVM
 
Ad

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); }