Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <locale.h>
- #define MAXLEN 100 // максимальная длина строки
- // структура одной строки
- struct Line{
- char name[MAXLEN]; // название впадины суши
- int depth; // глубина
- char location[MAXLEN]; // местоположение
- };
- // сортировка выбором
- void selection_sort(struct Line * list, int N){
- int index;
- for(int i = 0; i < N - 1; i++){
- index = i;
- for(int j = i + 1; j < N; j++){
- if(list[j].depth < list[index].depth){
- index = j;
- }
- }
- struct Line tmp = list[i];
- list[i] = list[index];
- list[index] = tmp;
- }
- }
- int main(){
- setlocale(0, ""); // русский язык
- int N = 15;
- struct Line * list = (struct Line *) malloc(N * sizeof(struct Line)); // выделяем память под массив типа Line размера N
- printf("Глубочайшие впадины суши\nВведите %d строк:\n", N);
- for(int i = 0; i < N; i++){
- scanf("%s%d%s", &list[i].name, &list[i].depth, &list[i].location);
- }
- selection_sort(list, N); // сортируем
- printf("Отсортированный список:\n");
- // построчно выводим
- for(int i = 0; i < N; i++){
- printf("%s %d %s\n", list[i].name, list[i].depth, list[i].location);
- }
- free(list); // освобождаем память
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment