File:Бинарное дерево.png

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Бинарное_дерево.png(637 × 318 pixels, file size: 10 KB, MIME type: image/png)

Captions

Captions

Add a one-line explanation of what this file represents

Summary[edit]

Description
Русский: Бинарное дерево
English: binary tree. Here H = shift down during one iteration, and iteration = number of iterations
Date
Source Own work
Author Владислав Молдован

Pascal src code[edit]

  • H - смещение вниз во время одной итерации
  • Iterations - количество итераций
uses GraphABC;
const
  H = 50;
  Iterations = 6;

procedure DrawTree(x, y, dx, iterations: integer);
begin
  if iterations > 0 then 
  begin
    var xm := x - dx;
    var xp := x + dx;
    var yp := y + H;
    
    Line(x, y, xm, yp);
    Line(x, y, xp, yp);
    
    Dec(iterations);
    dx := dx div 2;
    DrawTree(xm, yp, dx, iterations);
    DrawTree(xp, yp, dx, iterations);
  end;
end;

begin
  var W := Window.Width;
  
  SetWindowIsFixedSize(true);
  SetWindowHeight(20 + Iterations * H);
  ClearWindow(clBlack);
  
  SetPenColor(clGreenYellow);
  LockDrawing();
  DrawTree(W div 2, 10, W div 5, Iterations);
  Redraw();
end.
{Адаптировано под PascalABC 3.0.1.35.}
uses GraphABC;
const
  H = 50;
  Iterations = 6;

procedure DrawTree(x, y, dx, iterations: integer);
var
  xm, xp, yp: integer;

begin
  if iterations > 0 then
  begin
    xm := x - dx;
    xp := x + dx;
    yp := y + H;

    Line(x, y, xm, yp);
    Line(x, y, xp, yp);

    Dec(iterations);
    dx := dx div 2;
    DrawTree(xm, yp, dx, iterations);
    DrawTree(xp, yp, dx, iterations);
  end;
end;

var
  W: integer;

begin
  W := WindowWidth();

  SetWindowHeight(20 + Iterations * H);
  ClearWindow(clBlack);

  SetPenColor(clGreen);
  LockDrawing();
  DrawTree(W div 2, 10, W div 5, Iterations);
  Redraw();
end.

Licensing[edit]

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current09:32, 1 September 2017Thumbnail for version as of 09:32, 1 September 2017637 × 318 (10 KB)Владислав Молдован (talk | contribs)User created page with UploadWizard

There are no pages that use this file.

File usage on other wikis

The following other wikis use this file:

Metadata