You are on page 1of 2

#include <iostream>

#include<cstdlib>
#include <conio.h>
using namespace std;
void intercambio (int *A,int n){
int temp;
for (int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
if(A[i]>A[j]){
temp = A[i];
A[i]=A[j];
A[j]= temp;
};
};
};
};
void seleccion (int *A,int n){
int menor,indice,temp;
for(int i=0;i<n-1;i++){
menor = A[i];
indice = i;
for(int j=i+1;j<n;j++){
if (menor >A[j]){
menor = A[j];
indice = j;
};
};
temp = A[i];
A[i]=menor;
A[indice] = temp;
};
};
void insercion (int *A,int n){
int j,temp;
for (int i=0;i<n;i++){
temp = A[i];
for(j=i-1;j>=0 && temp<A[j];j--){
A[j+1] = A[j];
};
A[j+1]=temp;
};
};
void burbuja(int *A,int n){
int temp;
for(int i=0;i<n-1;i++){
for(int j=0;j<n-1-i;j++){
if(A[j]>A[j+1]){
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;
};
};
};
};
int main(){
int opcion,n,*A;
char c;
do{
cout<<"\nIngresa el tama�o del arreglo: ";cin>>n;
A = new int [n];
//elementos del arreglo
for(int i=0;i<n;i++){
cout<< " A["<<i<<"]: ";cin>>A[i];
};
do{
cout<<"\n\tElige el metodo para ordenar el arreglo."<<endl;
cout<<"1. INTERCAMBIO"<<endl<<"2. SELECCION"<<endl<<"3.
INSERCION"<<endl<<"4. BURBUJA"<<endl;cin>>opcion;
}while((opcion<1 )|| (opcion>4));
switch (opcion){
case 1:intercambio (A,n);
cout<<"\n Los elementos ordenados por el metodo de
intercambio son: \n";
break;
case 2:seleccion (A,n);
cout<<"\n Los elementos ordenados por el metodo de
seleccion son: \n";
break;
case 3:insercion (A,n);
cout<<"\n Los elementos ordenados por el metodo de
insercion son: \n";
break;
case 4:burbuja (A,n);
cout<<"\n Los elementos ordenados por el metodo de burbuja
son: \n";
break;
};
for (int i=0; i<n; i++){
cout<< " "<<A[i]<<" ";
};

cout<< "\nPresiona ""esc"" para terminar"<<endl;

c = getch();
}while(27!=c);

return 0;
}

You might also like