1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <stdio.h>
using namespace std;
void bubbleSort(int bubble[], int SIZE);
void selectSort();
const int SIZE = 8;
int main()
{
int bubble[SIZE] = {2, 0, 4, 5, 7, 6, 1, 3};
int select[SIZE] = {3, 4, 7, 0, 1, 2, 6, 5};
for (int i = 0; i < SIZE; i++){
cout << bubble[i];
bubbleSort(bubble, SIZE);
}
cout << endl;
cout << "\tNow the array will be sorting using the select sort algorithm.";
cout << endl;
for (int i = 0; i < SIZE; i++){
cout << select[i];
}
return 0;
}
void bubbleSort(int bubble[], int SIZE)
{
int temp;
bool madeAswap;
do
{
madeAswap = false;
for (int k = 0; k < (SIZE - 1); k++)
{
if (bubble[k] > bubble[k + 1])
{
temp = bubble[k];
bubble[k] = bubble[k + 1];
bubble[k + 1] = temp;
madeAswap = true;
for (int k = 0; k < (SIZE); k++)
cout << bubble[k];
}
}
}while (madeAswap);
}
|