Логин: Пароль:    Регистрация Всеми возможностями сайта можно пользоваться
только после авторизации.
   Забыли пароль?

Поиск
L



Статистика
u
Пользователи онлайн: нет
Гостей онлайн: 6
Всего онлайн: 6
Зарегистрировано юзеров: 7940
Комментариев на сайте: 698
Новый юзер: kotya.volkova



Последние комментарии
c
Dennisvoifs прокомментировал "Урок 3 - Конструкция IF...THEN...ELSE":
Пункт коммерческого учета цена, Ктп комплектные трансформаторные подстанции москва, Производство ктп москва и не только Вы найдете на нашем специализированном сайте: - Вам к нам!https://sviloguzov.ru/
Arthurneime прокомментировал "Урок 53 - Потоки в Delphi, (часть 1/3)":
[img]https://masterfutures.ru/wp-content/uploads/2020/03/14-2.png[/img] Online trading is becoming increasingly popular, as more people learn of the earning potential of platforms such as Broker, a broker which caters to a significant audience of digital traders (12 million and counting). Known for their excellent user interface, as well as fast deposit and withdrawal times, Broker provides multiple features to help traders earn on the markets. This overview will outline just some of the key aspects traders can expect to enjoy whilst working with Broker broker. Online trading is becoming increasingly popular, as more people learn of the earning potential of platforms such as Broker, a broker which caters to a significant audience of digital traders (12 million and counting). Known for their excellent user interface, as well as fast deposit and withdrawal times, Broker provides multiple features to help traders earn on the markets. This overview will outline just some of the key aspects traders can expect to enjoy whilst working with Broker broker. Broker Broker is operated by a dedicated team, whose main priority has always been to provide the best possible user experience, and ultimately satisfaction. Whether experienced in trading or a newcomer, the platform is easy to use and very responsive. The education section deserves special mention, particularly for assisting traders to learn and implement new strategies – which can be tested on the platforms free demo Source: [url=https://bit.ly/35fv3B6/]Broker[/url] https://bit.ly/35fv3B6/ Tags: Broker

Пирамидальная сортировка

Алгоритм пирамидальной сортировки (heapsort) — один из самых быстрых алгоритмов сортировки.

Program heapsort; 
 
{$APPTYPE CONSOLE} 
 
type 
  tkey = integer; 
  int = integer; 
 
const N = 10;   
 
var a,b : array [0..N+1] of tkey; 
 
function parent(x : int) : int; 
begin 
  result:=x shr 1; 
end; 
 
function left(x : int) : int; 
begin 
  result := x shl 1; 
  if result > a[0] then result := N+1; 
end; 
 
function right(x:int):int; 
begin 
  result := x shl 1 + 1; 
  if result > a[0] then result := N+1; 
end; 
 
procedure swap(i,j : int); 
var temp : tkey; 
begin 
  temp := a[i]; 
  a[i] := a[j]; 
  a[j] := temp; 
end; 
 
procedure moveup(x : int); 
begin 
  while (a[x] > a[parent(x)]) and (parent(x) > 0)  do begin 
    swap(x, parent(x)); 
    x := parent(x); 
  end; 
end; 
 
procedure movedown(x : int); 
var max : integer; 
begin 
  if a[left(x)] > a[right(x)] then max := left(x) 
  else max := right(x); 
  while (a[max] > a[x]) and (max <= a[0]) do begin 
    swap(max, x); 
    x := max; 
    if a[left(x)] > a[right(x)] then max := left(x) 
    else max := right(x); 
  end; 
end; 
 
 
procedure update(x : int; k : tkey); 
begin 
  a[x] := k; 
  moveup(x); 
  movedown(x); 
end; 
 
procedure add(k : tkey); 
begin 
  inc(a[0]); 
  update(a[0], k); 
end; 
 
procedure delete(x : int); 
begin 
  swap(x, a[0]); 
  dec(a[0]); 
  update(x, a[x]); 
end; 
 
procedure hsort; 
var i:int; 
begin 
  a[0] := 1; 
  a[1] := b[1]; 
  for i := 2 to N do 
    add(b[i]); 
  for i := 1 to N do 
    delete(1); 
end; 
 
var i : int; 
 
begin 
  randomize; 
  fillchar(a, sizeof(a), 0); 
  fillchar(b, sizeof(b), 0);   
 
  for i := 1 to N do 
    b[i] := random(10); 
 
  writeln('Non-sorted elements'); 
  for i := 1 to N do 
    write(b[i], ' '); 
  writeln; 
 
  hsort; 
 
  writeln('Sorted elements'); 
  for i := 1 to N do 
    write(a[i], ' '); 
  readln; 
end.

Вот и всё, Удачи!

Источник: www.thedelphi.ru
Автор: Савельев Александр
Опубликовано: 04 Октября 2014
Просмотров: 5896


Зарегистрируйтесь или авторизуйтесь, чтобы добавлять комментарии.