algoritmo de ordenacion recursiva

Rebollo
06 de Abril del 2004
pos eso, necesito un algoritmo d ordenacion recursiva pa una practica d la carrera. gracias

noel solw
06 de Abril del 2004
Te envio un programa que realiza ordenamiento recursivo por el sistema de las burbujas.

// program k7b1.CPP - page 127
// recursion : bubble sorting.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// written in Borland CPP ver 3.1

#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>

#define MAX 18

int a[MAX];

void MakeArray()
{
randomize();
for(int i = 0; i < MAX; i++)
a[i] = random(100);
} // MAKE ARRAY

void ShowArray(int n)
{
cout << "[" << setw(2) << n << "] :";
for(int i = 0; i < MAX; i++)
cout << setw(4) << a[i];
cout << endl;
} // SHOW ARRAY

void Swap(int &a,int &b)
{
int c = a;
a = b;
b = c;
} // SWAP

void BubbleSort(int LastIndex)
{
if(!LastIndex)
return;
BubbleSort(LastIndex-1);
for(int i = LastIndex; i && a[i-1] > a[i];i--)
Swap(a[i-1],a[i]);
ShowArray(LastIndex);
} // BUBBLE SORT

void main()
{
clrscr();
cout << "recursion : bubble sorting."
<< endl << endl;
MakeArray();
ShowArray(0);
BubbleSort(MAX-1);
cout << endl << "end of program - good bye ! ! !" << endl;
getch();
} // MAIN

/*
recursion : bubble sorting.

[ 0] : 82 1 38 38 25 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 1] : 1 82 38 38 25 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 2] : 1 38 82 38 25 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 3] : 1 38 38 82 25 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 4] : 1 25 38 38 82 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 5] : 1 25 38 38 82 96 29 49 96 49 76 99 56 98 34 56 22 32
[ 6] : 1 25 29 38 38 82 96 49 96 49 76 99 56 98 34 56 22 32
[ 7] : 1 25 29 38 38 49 82 96 96 49 76 99 56 98 34 56 22 32
[ 8] : 1 25 29 38 38 49 82 96 96 49 76 99 56 98 34 56 22 32
[ 9] : 1 25 29 38 38 49 49 82 96 96 76 99 56 98 34 56 22 32
[10] : 1 25 29 38 38 49 49 76 82 96 96 99 56 98 34 56 22 32
[11] : 1 25 29 38 38 49 49 76 82 96 96 99 56 98 34 56 22 32
[12] : 1 25 29 38 38 49 49 56 76 82 96 96 99 98 34 56 22 32
[13] : 1 25 29 38 38 49 49 56 76 82 96 96 98 99 34 56 22 32
[14] : 1 25 29 34 38 38 49 49 56 76 82 96 96 98 99 56 22 32
[15] : 1 25 29 34 38 38 49 49 56 56 76 82 96 96 98 99 22 32
[16] : 1 22 25 29 34 38 38 49 49 56 56 76 82 96 96 98 99 32
[17] : 1 22 25 29 32 34 38 38 49 49 56 56 76 82 96 96 98 99

end of program - good bye ! ! !
*/