fork download
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. class Main
  5. {
  6. class LinkedList<Type>
  7. {
  8.  
  9. private Node<Type> sentinel = new Node<Type>();
  10. private Node<Type> current;
  11. private int modCount;
  12.  
  13. public LinkedList()
  14. {
  15. // initialise instance variables
  16. sentinel.setNext(sentinel);
  17. sentinel.setPrev(sentinel);
  18. modCount = 0;
  19. }
  20. public void prepend(Type newData)
  21. {
  22. Node<Type> newN = new Node<Type>(newData);
  23. Node<Type> temp;
  24. temp = sentinel.getPrev();
  25. sentinel.setPrev(newN);
  26. temp.setNext(newN);
  27. newN.setPrev(temp);
  28. newN.setNext(sentinel);
  29. modCount++;
  30. }
  31.  
  32.  
  33. private class ListIterator implements Iterator<Type>
  34. {
  35. private int curPos, expectedCount;
  36. private Node<Type> itNode;
  37. private ListIterator()
  38. {
  39. curPos =0;
  40. expectedCount = modCount;
  41. itNode = sentinel;
  42. }
  43.  
  44. public boolean hasNext()
  45. {
  46. return (curPos < expectedCount);
  47. }
  48.  
  49. public Type next()
  50. {
  51. if (modCount != expectedCount)
  52. throw new ConcurrentModificationException("Cannot mutate in context of iterator");
  53. if (!hasNext())
  54. throw new NoSuchElementException("There are no more elements");
  55. itNode = itNode.getNext();
  56. curPos++;
  57. current = itNode;
  58. return (itNode.getData());
  59. }
  60.  
  61. @Override
  62. public void remove() {
  63. // TODO Auto-generated method stub
  64.  
  65. }
  66. }
  67.  
  68. private class Node<T> {
  69.  
  70. public Node(T newData) {
  71. // TODO Auto-generated constructor stub
  72. }
  73.  
  74. public Node<T> getPrev() {
  75. // TODO Auto-generated method stub
  76. return null;
  77. }
  78.  
  79. public Node() {
  80. // TODO Auto-generated constructor stub
  81. }
  82.  
  83. public Node<T> getNext() {
  84. return null;
  85. }
  86.  
  87. public void setNext(Node<T> next) {}
  88.  
  89. public void setPrev(Node<T> next) {}
  90.  
  91. public T getData() {
  92. // TODO Auto-generated method stub
  93. return null;
  94. }
  95.  
  96. }
  97. }
  98.  
  99.  
  100. public static void main (String[] args) throws java.lang.Exception
  101. {
  102.  
  103. }
  104. }
Success #stdin #stdout 0.07s 381184KB
stdin
Standard input is empty
stdout
Standard output is empty