Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.96 KB | None | 0 0
  1. unit BinTree;
  2.  
  3. interface
  4.  
  5. uses System.SysUtils, System.Types, Generics.Collections;
  6.  
  7. type
  8.    TNodeCoords = TList<TPoint>;
  9.  
  10. type
  11.    TComparator<TKey> = function(const A, B: TKey): ShortInt;
  12.    // negatiive: A < B; zero: A = B; positive: A > B
  13.  
  14.    TBinaryTree<K, V> = class
  15.    private type
  16.       PNode = ^TNode;
  17.  
  18.       TNode = record
  19.          Value: V;
  20.          Key: K;
  21.          PLeft, PRight: PNode;
  22.  
  23.          constructor Create(const Key: K; const Value: V);
  24.       end;
  25.  
  26.    function GetPreviousNode(const Key: K): PNode;
  27.    function GetPreReplaceNode(startNode: PNode): PNode;
  28.    function GetNodeCoords(Node: PNode): TNodeCoords;
  29.  
  30.    var
  31.       FCount: Integer;
  32.       Comparator: TComparator<K>;
  33.       PHead: PNode;
  34.    public
  35.       constructor Create(Comparator: TComparator<K>);
  36.       property Count: Integer read FCount;
  37.       procedure Add(const Key: K; const Value: V);
  38.       procedure Delete(const Key: K);
  39.  
  40.    end;
  41.  
  42. implementation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement