Necesito ayuda?
Necesito ayuda?
programa que genere no. alearotio
luego meterlos en una lista y ordenarlos
programa que genere no. alearotio
luego meterlos en una lista y ordenarlos
// program k4_5.CPP - page 70
// bubble sort.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// 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 :
25 29 11 29 26 49 99 35 44 51 82 10 73 74 24 44 95 77
25 11 29 26 29 49 35 44 51 82 10 73 74 24 44 95 77 99
11 25 26 29 29 35 44 49 51 10 73 74 24 44 82 77 95 99
11 25 26 29 29 35 44 49 10 51 73 24 44 74 77 82 95 99
11 25 26 29 29 35 44 10 49 51 24 44 73 74 77 82 95 99
11 25 26 29 29 35 10 44 49 24 44 51 73 74 77 82 95 99
11 25 26 29 29 10 35 44 24 44 49 51 73 74 77 82 95 99
11 25 26 29 10 29 35 24 44 44 49 51 73 74 77 82 95 99
11 25 26 10 29 29 24 35 44 44 49 51 73 74 77 82 95 99
11 25 10 26 29 24 29 35 44 44 49 51 73 74 77 82 95 99
11 10 25 26 24 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 25 24 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
end of program - good bye ! ! !
*/
// bubble sort.
// c++ exercices book - dr. gershon kagan (first edition : 2001)
// 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 :
25 29 11 29 26 49 99 35 44 51 82 10 73 74 24 44 95 77
25 11 29 26 29 49 35 44 51 82 10 73 74 24 44 95 77 99
11 25 26 29 29 35 44 49 51 10 73 74 24 44 82 77 95 99
11 25 26 29 29 35 44 49 10 51 73 24 44 74 77 82 95 99
11 25 26 29 29 35 44 10 49 51 24 44 73 74 77 82 95 99
11 25 26 29 29 35 10 44 49 24 44 51 73 74 77 82 95 99
11 25 26 29 29 10 35 44 24 44 49 51 73 74 77 82 95 99
11 25 26 29 10 29 35 24 44 44 49 51 73 74 77 82 95 99
11 25 26 10 29 29 24 35 44 44 49 51 73 74 77 82 95 99
11 25 10 26 29 24 29 35 44 44 49 51 73 74 77 82 95 99
11 10 25 26 24 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 25 24 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
10 11 24 25 26 29 29 35 44 44 49 51 73 74 77 82 95 99
end of program - good bye ! ! !
*/
