Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template <typename T>
- void sort(T array[], int size) {
- for (int k = 0; k < size; k++) {
- for (int j = 0; j < size - k - 1; j++) {
- if (array[j] > array[j + 1]) {
- T temp = array[j];
- array[j] = array[j + 1];
- array[j + 1] = temp;
- }
- }
- }
- }
- template <typename T>
- void display(T array[], int size) {
- for (int i = 0; i < size; i++) {
- cout << array[i] << " ";
- }
- cout << endl;
- }
- int main() {
- setlocale(LC_ALL, "ru");
- int array[]{ 1, 3, 7, -4, -2, 4 };
- int size = 6;
- cout << "Original int Array : ";
- display(array, size);
- sort(array, size);
- cout << "Sorted int Array : ";
- display(array, size);
- double doublearray[]{ 3.5, 2.5, 3.7, 1.0, 3.3 };
- size = 5;
- cout << "Original double Array : ";
- display(doublearray, size);
- sort(doublearray, size);
- cout << "Sorted double Array : ";
- display(doublearray, size);
- char arr[]{ "Привет" };
- display(arr, 6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement