Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename T>
- void bubble_sort(T arr[], int size) {
- T temp;
- for (int k = 0; k < size; k++) {
- for (int j = 0; j < size - k - 1; j++) {
- if (arr[j] > arr[j + 1]) {
- temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- }
- template <typename T>
- void display(T arr[], int size) {
- for (int i = 0; i < size; i++) {
- cout << arr[i] << " ";
- }
- cout << endl;
- }
- int main() {
- const int size = 6;
- int arr1[6]{ 4,1,8,3,2,5 };
- double arr2[6]{ 2.3,-4.2,5.6,-3.7,8.4,-1.3 };
- display(arr1, size);
- bubble_sort(arr1, size);
- display(arr1, size);
- cout << endl << endl;
- display(arr2, size);
- bubble_sort(arr2, size);
- display(arr2, size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement