LinkedList.d.ts 861 B

123456789101112131415161718192021222324252627
  1. export declare class HeadNode<T> {
  2. next: LinkedListNode<T> | TailNode<T>;
  3. constructor();
  4. }
  5. export declare class TailNode<T> {
  6. previous: LinkedListNode<T> | HeadNode<T>;
  7. constructor(head: HeadNode<T>);
  8. }
  9. export declare class LinkedListNode<T> {
  10. next: LinkedListNode<T> | TailNode<T> | null;
  11. previous: LinkedListNode<T> | HeadNode<T> | null;
  12. readonly item: T;
  13. constructor(item: T);
  14. detachSelf(): void;
  15. attachAfter(node: LinkedListNode<T> | HeadNode<T>): void;
  16. attachBefore(node: LinkedListNode<T> | TailNode<T>): void;
  17. }
  18. export declare class LinkedList<T> {
  19. head: HeadNode<T>;
  20. tail: TailNode<T>;
  21. constructor();
  22. add(item: T): LinkedListNode<T>;
  23. getItems(): T[];
  24. forEach(callback: (item: T, node: LinkedListNode<T>) => void): void;
  25. hasItems(): boolean;
  26. getLastItem(): LinkedListNode<T>;
  27. }