Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int Eval(string a, string b) {
  8.     if (a.length() > b.length()) return 1;
  9.     else if (a.length() < b.length()) return 2;
  10.     else return 0;
  11. }
  12.  
  13. template<typename T1, typename T2>
  14. int Eval(T1 a, T2 b) {
  15.     if (a > b) return 1;
  16.     else if (a < b) return 2;
  17.     else return 0;
  18. }
  19. // Пузырьковая сортировка
  20.  
  21. int *sort(int a[], const int n) {
  22.     for (int i = 0; i < n; i++) {
  23.         for (int j = 0; j < n; j++) {
  24.             int res = Eval(a[i], a[j]);
  25.             if (res == 2) swap(a[i], a[j]);
  26.         }
  27.     }
  28.     return &a[0];
  29. }
  30.  
  31. int main() {
  32.     // Сравнение чисел
  33.     int a = 1, b = 1;
  34.     int res = Eval(a, b);
  35.     cout << res << "\n";
  36.     // Сравнение дробных чисел
  37.     float c = 2.0004, d = 2.0003;
  38.     int res2 = Eval(c, d);
  39.     cout << res2 << "\n";
  40.     // Сравнение строк
  41.     string arr1 = "abc", arr2 = "abcdef";
  42.     int res3 = Eval(arr1, arr2);
  43.     cout << res3 << "\n";
  44.     // Сортировка массива
  45.     int array[] = {6, 5, 4, 3, 2, 1};
  46.     int *sort_array = sort(array, 6);
  47.     for (int i = 0; i < 6; i++) {
  48.         cout << sort_array[i] << " ";
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement