#include <iostream>#include <ctime>using namespace std;int inicial (int o[], int c);void llenar (int b[10]);void menu()...
}           b[i]=num;     }}void menu(){      cout<<"INGRESE SU OPCION SEGUN EL METODO DE ORDENAMIENTO DESDEADO:"<<endl;  ...
for(int l=0;l<9;l++){           pos_m=inicial(k,l);           if(k[l]>k[pos_m]){                 m=k[pos_m];              ...
Upcoming SlideShare
Loading in …5
×

Practica 4 errores

199 views
150 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
199
On SlideShare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Practica 4 errores

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

×