› Foros › PC › Software libre
#ifndef _ARRAY_H_
#define _ARRAY_H_
#pragma once
#include<string>
#include<iostream>
#include<vector>
#define SELECCION 1
#define BURBUJA 2
#define SHELL 3
#define QUICKSHORT 4
#define HEAPSORT 5
using namespace std;
template <typename T>
class Array : public vector<T>{
void OrdenarSeleccion();
void OrdenarBurbuja();
void OrdenarShell() ;
void OrdenarQuicshort() ;
void OrdenarHeapsort() ;
void BuscarLineal()const;
void BuscarBinaria()const;
void intercambiar(int pos1, int pos2);
public:
Array(int capacidad);
void Ordenar(int tipo);
bool Buscar(int tipo) const;
};
Array<int> generaAleatorio(int talla);
#endif
#include "StdAfx.h"
#include "Array.h"
#include <time.h>
template <typename T>
Array<T>::Array(int capacidad):vector<T>(capacidad){
};
template <typename T>
void Array<T>::OrdenarSeleccion(){
for (int i=0; i<this.size(); i++){
T minimo=this[i];
int Pminimo=i;
for (int k=0; k<this.size();k++){
if(this[k]<minimo){
minimo=this[k];
Pminimo=k;
}
}
intercambiar(i,Pminimo);
}
}
template <typename T>
void Array<T>::OrdenarBurbuja(){
}
template <typename T>
void Array<T>::OrdenarShell(){
}
template <typename T>
void Array<T>::OrdenarQuicshort(){
}
template <typename T>
void Array<T>::OrdenarHeapsort(){
}
template <typename T>
void Array<T>::BuscarLineal()const{
}
template <typename T>
void Array<T>::BuscarBinaria()const{
}
template <typename T>
void Array<T>::Ordenar(int tipo){
switch (tipo){
case SELECCION: OrdenarSeleccion(); break;
default : break;
}
}
template <typename T>
bool Array<T>::Buscar(int tipo) const{
}
template <typename T>
void Array<T>::intercambiar(int pos1, int pos2){
T aux;
aux=this[pos1];
this[pos2]=this[pos1];
this[pos1]=aux;
}
Array<int> generaAleatorio(int talla){
Array<int> a(talla);
srand(time(NULL));
for (int i=0; i<talla; i++){
a[i]=rand()%1000;
}
return a;
}
#include "stdafx.h"
#include "Array.h"
int _tmain(int argc, _TCHAR* argv[])
{
Array<int> a(200);
for (int i=0; i<200; i++){
a[i]=i;
}
for (int i=0; i<200; i++){
cout <<a[i]<<endl;
}
a.Ordenar(0);
system("pause");
return 0;
}