{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# bubsort - int temp int input_size = input_vector.length...

This preview shows pages 1–2. Sign up to view the full content.

// bubsort.cpp // An implementation of a bubble sort algorithm. / // compiler directives #include<iostream.h> #include"apvector.h" # // function prototypes void bubble_sort(apvector <int> &input_vector); void display_array(apvector <int> input_vector); v int main() { apvector <int> nums(5); nums[0] = 20; nums[1] = 31; nums[2] = 17; nums[3] = 47; nums[4] = 14; cout << "Unsorted vector:\n"; display_array(nums); bubble_sort(nums); cout << "Sorted vector:\n"; display_array(nums); return 0; } // Bubble sort function. Sorts a vector of ints in descending order. void bubble_sort(apvector <int> &input_vector) { int i, j, flag = 1;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int temp; int input_size = input_vector.length(); for(i = 1; (i <= input_size) && flag; i++) { flag = 0; for(j = 0; j < (input_size - i); j++) { if (input_vector[j + 1] > input_vector[j]) { temp = input_vector[j + 1]; input_vector[j + 1] = input_vector[j]; input_vector[j] = temp; flag = 1; } } } } // Function that simply displays each element of input_array. void display_array(apvector <int> input_vector) { int i; int input_size = input_vector.length(); for (i = 0; i < input_size; i++) { cout << input_vector[i] << ' '; } cout << "\n\n"; }...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

bubsort - int temp int input_size = input_vector.length...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online