Advertisement
35657

Untitled

Dec 14th, 2023
810
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. template <typename T>
  6. void sort(T array[], int size) {
  7.     for (int k = 0; k < size; k++) {
  8.         for (int j = 0; j < size - k - 1; j++) {
  9.             if (array[j] > array[j + 1]) {
  10.                 T temp = array[j];
  11.                 array[j] = array[j + 1];
  12.                 array[j + 1] = temp;
  13.             }
  14.         }
  15.     }
  16. }
  17.  
  18. template <typename T>
  19. void display(T array[], int size) {
  20.     for (int i = 0; i < size; i++) {
  21.         cout << array[i] << " ";
  22.     }
  23.     cout << endl;
  24. }
  25.  
  26. void display(char array[], int size) {
  27.     for (int i = 0; i < size; i++) {
  28.         cout << array[i];
  29.     }
  30.     cout << endl;
  31. }
  32.  
  33. int main() {
  34.     setlocale(LC_ALL, "ru");
  35.  
  36.     int array[]{ 1, 3, 7, -4, -2, 4 };
  37.     int size = 6;
  38.     cout << "Original int Array : ";
  39.     display(array, size);
  40.     sort(array, size);
  41.     cout << "Sorted   int Array : ";
  42.     display(array, size);
  43.  
  44.  
  45.     double doublearray[]{ 3.5, 2.5, 3.7, 1.0, 3.3 };
  46.     size = 5;
  47.     cout << "Original double Array : ";
  48.     display(doublearray, size);
  49.     sort(doublearray, size);
  50.     cout << "Sorted double Array : ";
  51.     display(doublearray, size);
  52.  
  53.     char arr[]{ "Привет" };
  54.     display(arr, 6);
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement