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
|
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
//member function
void insertion_sort(int array[], int length);
void print_array(int array[],int size);
void print_vector(vector<int>& my_vector);
int main()
{
int i;
int my_array[10]= {63, 42, 27, 111, 55, 14, 66, 9, 75, 87};
vector<int> my_vector;
insertion_sort(my_array,10);
return 0;
}
void insertion_sort(int array[], int length) {
int x,y,z;
for (x = 0; x < length; x++) {
y = x;
while (y > 0 && array[y - 1] > array[y]) {
z = array[y];
array[y] = array[y - 1];
array[y - 1] = z;
y--;
}
print_array(array,10);
}//end of for loop
}//end of insertion_sort.
void print_array(int array[], int size)
{
cout<< "Please wait while sorting " << ": ";
int s;
for (s=0; s<size;s++)
for (s=0; s<size;s++)
cout <<" "<< array[s];
cout << endl;
}//end of print_array
void print_vector(vector<int>& my_vector)
{
}
|