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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
# include <iostream>
#include <string>
using namespace std;
//functio prototypes
void printList(int [], const int);
void sortList(int [], const int);
void bubbleSort(int[], const int);
void main()
{
const int SIZE_OF_ARRAY=5;
int order_List[SIZE_OF_ARRAY]={21,13,17,5,3};
// shows the unsorted index
cout<<"Unsorted : ";
printList(order_List, SIZE_OF_ARRAY);
cout<<endl;
//shows the sort and passes
string passes[4]={"first","second","third","fourth"};
for(int j=0;j<4;j++)
{
cout<<"This is the ";
cout<< passes[j]<<" pass: ";
bubbleSort(order_List,SIZE_OF_ARRAY);
cout<<endl;
}
//shows the sorted index
cout<<"sorted Index : ";
printList(order_List, SIZE_OF_ARRAY);
cout<<endl;
}
//function PrintList Defintion
void printList(int order_List_2[],const int SIZE)
{
for(int count=0; count<SIZE;count++)
{
cout<<order_List_2[count]<<" ";
}
cout<<endl;
}
//function bubblesort definiton
void bubbleSort(int sorting_list[], int SIZE1)
{
//const int SIZE_OF_ARRAY=5;
//int order_List[SIZE_OF_ARRAY]={21,13,17,5,3};
sortList(sorting_list,SIZE1);
printList(sorting_list,SIZE1);
}
void sortList(int sortlist[], const int SIZE2)
{
int place_holder;
if(sortlist[0]>=sortlist[1])
{
place_holder=sortlist[0];
sortlist[0]=sortlist[1];
sortlist[1]=place_holder;
}
if(sortlist[1]>=sortlist[2])
{
place_holder=sortlist[1];
sortlist[1]=sortlist[2];
sortlist[2]=place_holder;
}
if(sortlist[2]>=sortlist[3])
{
place_holder=sortlist[2];
sortlist[2]=sortlist[3];
sortlist[3]=place_holder;
}
if(sortlist[3]>=sortlist[4])
{
place_holder=sortlist[3];
sortlist[3]=sortlist[4];
sortlist[4]=place_holder;
}
}
|