File:Двоичное дерево.png

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

Двоичное_дерево.png(409 × 225 pixels, file size: 4 KB, MIME type: image/png)

Captions

Captions

Binary tree

Summary[edit]

Description
Русский: Двоичное дерево
English: Binary tree
Date
Source Own work
Author Владислав Молдован

source code[edit]

uses GraphABC; 
const
  Angle = -Pi / 4;

type
  EdgeData = auto class
    A, B, C: Point;
    R: integer;
  end;

var
  DataStack: Stack<EdgeData>;

function RotatePoint(pA: Point; r, angle: integer): Point;
begin
  var angle2 := DegToRad(angle);
  Result := new Point(Round(pA.X + r * Cos(angle2)), Round(pA.Y + r * Sin(angle2)));
end;

procedure PushTreePart(pB: Point; r: integer):=DataStack.Push(new EdgeData(RotatePoint(pB, r, -135), pB, RotatePoint(pB, r, -45), r));

function RIsBig(dt: EdgeData):= dt.R > 5;

begin
  LockDrawing();
  
  DataStack := new Stack<EdgeData>();
  
  PushTreePart(new Point(300, 300), 200);
  while DataStack.Count > 0 do
  begin
    var dt := DataStack.Pop();
    
    var pD := new Point((dt.A.X + dt.C.X) div 2, (dt.A.Y + dt.C.Y) div 2);
    Line(dt.A.X, dt.A.Y, dt.C.X, dt.C.Y);
    Line(pD.X, pD.Y, dt.B.X, dt.B.Y);
    
    if RIsBig(dt) then
    begin
      var r2 := dt.R div 2;
      PushTreePart(dt.A, r2);
      PushTreePart(dt.C, r2);
    end;
  end;
  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 2017409 × 225 (4 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