metodo de burbuja
necesito el metodo de burbuja en c, que muestre los movimientos que realiza
// program k4_5.CPP - page 70
// bubble sort.
// 28/7/2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define MAX 18
void Show(int *a)
{
for(int i = 0; i < MAX; i++)
cout << setw(4) << a[i];
cout << endl;
} // SHOW
void Init(int *a)
{
for(int i = 0; i < MAX; i++)
a[i] = random(100);
} // INIT
void Swap(int &a,int &b)
{
int c = a;
a = b;
b = c;
} // SWAPS INTEGER
void BubbleSort(int *a)
{
for(int top = MAX-1; top; top--)
{
for(int i = 0; i < top; i++)
if (a[i] > a[i+1])
Swap(a[i],a[i+1]);
Show(a);
}
} // BUBBLE SORT
void main()
{
clrscr();
randomize();
int a[MAX];
cout << "bubble sort : " << endl << endl;
Init(a);
Show(a);
cout << endl;
BubbleSort(a);
cout << endl << "end of program - good bye ! ! !n";
getch();
} // MAIN
// bubble sort.
// 28/7/2001
// written in Borland CPP ver 3.1
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#define MAX 18
void Show(int *a)
{
for(int i = 0; i < MAX; i++)
cout << setw(4) << a[i];
cout << endl;
} // SHOW
void Init(int *a)
{
for(int i = 0; i < MAX; i++)
a[i] = random(100);
} // INIT
void Swap(int &a,int &b)
{
int c = a;
a = b;
b = c;
} // SWAPS INTEGER
void BubbleSort(int *a)
{
for(int top = MAX-1; top; top--)
{
for(int i = 0; i < top; i++)
if (a[i] > a[i+1])
Swap(a[i],a[i+1]);
Show(a);
}
} // BUBBLE SORT
void main()
{
clrscr();
randomize();
int a[MAX];
cout << "bubble sort : " << endl << endl;
Init(a);
Show(a);
cout << endl;
BubbleSort(a);
cout << endl << "end of program - good bye ! ! !n";
getch();
} // MAIN
