Advertisement
MeShootIn

6

Feb 28th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. /*
  2. ЛАБОРАТОРНАЯ РАБОТА № 6
  3. ВАРИАНТ 20
  4. ВЫПОЛНИЛ: ДМИТРИЙ МИШУТИН КЭ - 101
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <iostream>
  9.  
  10. using namespace std;
  11.  
  12. const int N = 10;
  13.  
  14. struct list{
  15.     string city, region, country, date;
  16.     int S, population;
  17. } arr[N];
  18.  
  19. void swap_list(list &a, list &b){
  20.     list tmp = a;
  21.     a = b;
  22.     b = tmp;
  23. }
  24.  
  25. void bubble_sort_1(list * arr, int N){
  26.     for(int i = 0; i < N - 1; i++){
  27.         for(int j = 0; j < N - i - 1; j++){
  28.             if(arr[j].city > arr[j + 1].city){
  29.                 swap_list(arr[j], arr[j + 1]);
  30.             }
  31.         }
  32.     }
  33. }
  34.  
  35. void bubble_sort_2(list * arr, int N){
  36.     for(int i = 0; i < N - 1; i++){
  37.         for(int j = 0; j < N - i - 1; j++){
  38.             if(arr[j].population > arr[j + 1].population){
  39.                 swap_list(arr[j], arr[j + 1]);
  40.             }
  41.         }
  42.     }
  43. }
  44.  
  45. int main(){
  46.     setlocale(0, "");
  47.    
  48.     printf("Введите таблицу (город, субъект, страна, дата основания, площадь, население):\n");
  49.     for(int i = 0; i < N; i++){
  50.         cin >> arr[i].city >> arr[i].region >> arr[i].country >> arr[i].date >> arr[i].S >> arr[i].population;
  51.     }
  52.    
  53.     bubble_sort_1(arr, N);
  54.     bubble_sort_2(arr, N);
  55.    
  56.     for(int i = 0; i < N; i++){
  57.         cout << arr[i].city << " " << arr[i].region << " " << arr[i].country << " " << arr[i].date << " " << arr[i].S << " " << arr[i].population << endl;
  58.     }
  59.    
  60.     system("PAUSE");
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement