Guest User

Untitled

a guest
Jul 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. declare module 'linked-list' {
  2. export default LinkedList;
  3.  
  4. export interface ListItem {
  5. next: ListItem;
  6.  
  7. prev: ListItem;
  8.  
  9. list: LinkedList | null;
  10.  
  11. append (item: ListItem): ListItem;
  12.  
  13. detach (): boolean;
  14.  
  15. prepend (item: ListItem): ListItem;
  16. }
  17.  
  18. class LinkedList {
  19.  
  20. head: ListItem;
  21. tail: ListItem;
  22.  
  23. /** Creates a new List: A linked list is a bit like an Array,
  24. * but knows nothing about how many items are in it, and
  25. * knows only about its first (`head`) and last (`tail`)
  26. * items. Each item (e.g. `head`, `tail`, &c.) knows which
  27. * item comes before or after it (its more like the
  28. * implementation of the DOM in JavaScript).
  29. * @param [items]
  30. */
  31. constructor (...items: ListItem[]);
  32.  
  33. static from (items: ListItem[]): LinkedList;
  34.  
  35. static of (...items: ListItem[]): LinkedList;
  36.  
  37. append (item: ListItem): ListItem;
  38.  
  39. prepend (item: ListItem): ListItem;
  40.  
  41. toArray (): any[];
  42.  
  43. }
  44.  
  45. namespace LinkedList {
  46. class Item implements ListItem {
  47. list: LinkedList | null;
  48. next: ListItem;
  49. prev: ListItem;
  50.  
  51. constructor ();
  52.  
  53. append (item: ListItem): ListItem;
  54.  
  55. detach (): boolean;
  56.  
  57. prepend (item: ListItem): ListItem;
  58.  
  59. }
  60. }
  61.  
  62. }
Add Comment
Please, Sign In to add comment