Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- int Eval(string a, string b) {
- if (a.length() > b.length()) return 1;
- else if (a.length() < b.length()) return 2;
- else return 0;
- }
- template<typename T1, typename T2>
- int Eval(T1 a, T2 b) {
- if (a > b) return 1;
- else if (a < b) return 2;
- else return 0;
- }
- // Пузырьковая сортировка
- int *sort(int a[], const int n) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- int res = Eval(a[i], a[j]);
- if (res == 2) swap(a[i], a[j]);
- }
- }
- return &a[0];
- }
- int main() {
- // Сравнение чисел
- int a = 1, b = 1;
- int res = Eval(a, b);
- cout << res << "\n";
- // Сравнение дробных чисел
- float c = 2.0004, d = 2.0003;
- int res2 = Eval(c, d);
- cout << res2 << "\n";
- // Сравнение строк
- string arr1 = "abc", arr2 = "abcdef";
- int res3 = Eval(arr1, arr2);
- cout << res3 << "\n";
- // Сортировка массива
- int array[] = {6, 5, 4, 3, 2, 1};
- int *sort_array = sort(array, 6);
- for (int i = 0; i < 6; i++) {
- cout << sort_array[i] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement