
Составить процедуру упорядочения массива (по возрастанию и убыванию)


Ответы на вопрос





procedure MassivSort(var arr : array of Real; const N : Integer);var I: Integer; J: Integer; K: Integer; M: Real;begin for i:=1 to N do begin m:=Arr[i-1]; k:=i; for j:=i to n do begin if m>Arr[j-1] then begin m:=Arr[j-1]; k:=j; end; end; Arr[k-1]:=Arr[i-1]; Arr[i-1]:=m; end;end;
Сортировка по убыванию:
procedure sort;
var i , j , tmp : integer;
begin
for i := 1 to n - 1 do
for j := i + 1 to n do
if a[i] < a[j] then begin
tmp := a[i];
a[i] := a[j];
a[j] := tmp;
end;



Procedure for Sorting an Array (Ascending and Descending Order)
To sort an array in ascending or descending order, you can use various algorithms such as bubble sort, selection sort, insertion sort, merge sort, quick sort, or heap sort. Here's a general procedure for sorting an array in both ascending and descending order:
1. Ascending Order: - Bubble Sort Algorithm: - Compare each pair of adjacent elements and swap them if they are in the wrong order. - Repeat this process for each element in the array until the entire array is sorted in ascending order.
- Selection Sort Algorithm: - Find the minimum element in the unsorted array and swap it with the first unsorted element. - Repeat this process for the remaining unsorted portion of the array until the entire array is sorted in ascending order.
- Insertion Sort Algorithm: - Iterate through the array and for each element, insert it into its correct position in the sorted array to the left of it.
- Merge Sort Algorithm: - Divide the unsorted array into n subarrays, each containing one element. - Repeatedly merge subarrays to produce new sorted subarrays until there is only one subarray remaining, which is the sorted array.
- Quick Sort Algorithm: - Choose a "pivot" element from the array and partition the other elements into two sub-arrays according to whether they are less than or greater than the pivot. - Recursively apply the quick sort algorithm to the sub-arrays.
- Heap Sort Algorithm: - Convert the array into a max-heap (for ascending order) or a min-heap (for descending order). - Repeatedly remove the root of the heap and place it at the end of the array until the heap is empty, resulting in a sorted array.
2. Descending Order: - To sort the array in descending order, you can use the same algorithms mentioned above but with modifications to the comparison and swapping logic.
- For example, in the bubble sort algorithm, you would compare each pair of adjacent elements and swap them if the first element is less than the second element, instead of the other way around as in the ascending order.
- Similarly, you would make corresponding modifications to the selection sort, insertion sort, merge sort, quick sort, and heap sort algorithms to achieve descending order.
This general procedure outlines the steps involved in sorting an array in both ascending and descending order using various sorting algorithms.
(#1)(#6)(#10)


Топ вопросов за вчера в категории Информатика
Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili