Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ЛАБОРАТОРНАЯ РАБОТА № 6
- ВАРИАНТ 20
- ВЫПОЛНИЛ: ДМИТРИЙ МИШУТИН КЭ - 101
- */
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- const int N = 10;
- struct list{
- string city, region, country, date;
- int S, population;
- } arr[N];
- void swap_list(list &a, list &b){
- list tmp = a;
- a = b;
- b = tmp;
- }
- void bubble_sort_1(list * arr, int N){
- for(int i = 0; i < N - 1; i++){
- for(int j = 0; j < N - i - 1; j++){
- if(arr[j].city > arr[j + 1].city){
- swap_list(arr[j], arr[j + 1]);
- }
- }
- }
- }
- void bubble_sort_2(list * arr, int N){
- for(int i = 0; i < N - 1; i++){
- for(int j = 0; j < N - i - 1; j++){
- if(arr[j].population > arr[j + 1].population){
- swap_list(arr[j], arr[j + 1]);
- }
- }
- }
- }
- int main(){
- setlocale(0, "");
- printf("Введите таблицу (город, субъект, страна, дата основания, площадь, население):\n");
- for(int i = 0; i < N; i++){
- cin >> arr[i].city >> arr[i].region >> arr[i].country >> arr[i].date >> arr[i].S >> arr[i].population;
- }
- bubble_sort_1(arr, N);
- bubble_sort_2(arr, N);
- for(int i = 0; i < N; i++){
- cout << arr[i].city << " " << arr[i].region << " " << arr[i].country << " " << arr[i].date << " " << arr[i].S << " " << arr[i].population << endl;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement