You are on page 1of 1

#include <iostream>

#include <fstream>

using std::fstream;
using namespace std;

template <typename ItemType>


void r_swap(ItemType& a, ItemType& b){
ItemType c(a);
a = b;
b = c;
}

template <typename ItemType>


void Bubble_Sort(ItemType* theArray, int n){
bool sorted = false;
int pass = 1;

while (!sorted && (pass < n)){


sorted = true;
for (int index = 0; index < n - pass; ++index) {
int nextIndex = index + 1;
if (theArray[index] > theArray[nextIndex]){
r_swap(theArray[index], theArray[nextIndex]);
sorted = false;
}
}
pass++;
}
}

int main() {

int size;
cout<<"Ingrese el tamaño : ";
cin>>size;

string *Ar = new string[size];

for (int i = 0; i < size; ++i) {


cout<<"ingrese "<<i + 1<<" : ";
cin>>Ar[i];
}

Bubble_Sort(Ar, size);

for (int i = 0; i < size; ++i) {


cout<<"numero "<<i + 1<<" : "<<Ar[i]<<endl;
}

system("pause");
return 0;
}

You might also like