fork download
  1. import java.io.*;
  2.  
  3. class element<T>
  4. {
  5. protected element<T> prev, next;
  6. protected T val;
  7.  
  8. public element()
  9. {
  10. prev = null;
  11. next = null;
  12. }
  13.  
  14. public element( T x )
  15. {
  16. prev = null;
  17. next = null;
  18. val = x;
  19. }
  20. }
  21.  
  22. class list<T> implements java.util.Collection<T>
  23. {
  24. private element<T> front, back;
  25. private int size;
  26.  
  27. public list()
  28. {
  29. front = new element<>();
  30. back = new element<>();
  31. size = 0;
  32.  
  33. front.prev = back;
  34. back.next = front;
  35. }
  36.  
  37. public void AddFront( T x )
  38. {
  39. front.val = x;
  40. front.next = new element<>();
  41. front.next.prev = front;
  42. front = front.next;
  43. size ++;
  44. }
  45.  
  46. public T RemoveFront()
  47. {
  48. front.prev.next = null;
  49. front = front.prev;
  50. size --;
  51. return front.val;
  52. }
  53.  
  54. public void AddBack( T x )
  55. {
  56. back.val = x;
  57. back.prev = new element<>();
  58. back.prev.next = back;
  59. back = back.prev;
  60. size ++;
  61. }
  62.  
  63. public T RemoveBack()
  64. {
  65. back.next.prev = null;
  66. back = back.next;
  67. size --;
  68. return back.val;
  69. }
  70.  
  71. public int size()
  72. {
  73. return size;
  74. }
  75.  
  76. public boolean add(T x)
  77. {
  78. AddFront( x );
  79. }
  80.  
  81. public void clear()
  82. {
  83. front = new element<>();
  84. back = new element<>();
  85. size = 0;
  86.  
  87. front.prev = back;
  88. back.next = front;
  89. }
  90. }
  91.  
  92. class testowanie
  93. {
  94. public static void main(String[] args)
  95. {
  96. list<String> x = new list<String>();
  97.  
  98. x.AddFront( "s" );
  99. x.AddFront( "i" );
  100. x.AddBack( "a" );
  101. x.AddBack( "b" );
  102. x.AddBack( "c" );
  103. x.AddBack( "d" );
  104. }
  105. }
Compilation error #stdin compilation error #stdout 0.04s 2184192KB
stdin
Standard input is empty
compilation info
Main.java:22: error: list is not abstract and does not override abstract method retainAll(Collection<?>) in Collection
class list<T> implements java.util.Collection<T>
^
1 error
stdout
Standard output is empty