fork download
  1. public class MyList {
  2. private Node head;
  3.  
  4. public MyList() {
  5. this.head = null;
  6. }
  7.  
  8. public void myRemove(int startIndex, int endIndex){
  9. startIndex--;
  10. for(int i = startIndex; i < endIndex; i++){
  11. this.remove(startIndex);
  12. }
  13. }
  14.  
  15. public int size(){
  16. int count = 0;
  17. Node node = head;
  18. while(node != null){
  19. node = node.getNext();
  20. count++;
  21. }
  22. return count;
  23. }
  24.  
  25. public void add(int value){
  26. Node node = head;
  27. if(node == null){
  28. head = new Node(value);
  29. return;
  30. }
  31. while(node.getNext() != null){
  32. node = node.getNext();
  33. }
  34. node.setNext(new Node(value));
  35. }
  36.  
  37. public int get(int index){
  38. int i = 0;
  39. Node node = head;
  40. while(node.getNext() != null && i < index){
  41. node = node.getNext();
  42. i++;
  43. }
  44. return node.getValue();
  45. }
  46.  
  47. public void remove(int index){
  48. if(index == 0 && head != null){
  49. head = head.getNext();
  50. return;
  51. }
  52. int i = 0;
  53. Node node = head;
  54. while(node.getNext() != null && i+1 < index){
  55. node = node.getNext();
  56. i++;
  57. }
  58. try{
  59. node.setNext(node.getNext().getNext());
  60. }catch(Exception ex){
  61. node.setNext(null);
  62. }
  63. }
  64. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class MyList is public, should be declared in a file named MyList.java
public class MyList {
       ^
Main.java:2: error: cannot find symbol
    private Node head;
            ^
  symbol:   class Node
  location: class MyList
Main.java:17: error: cannot find symbol
        Node node = head;
        ^
  symbol:   class Node
  location: class MyList
Main.java:26: error: cannot find symbol
        Node node = head;
        ^
  symbol:   class Node
  location: class MyList
Main.java:28: error: cannot find symbol
            head = new Node(value);
                       ^
  symbol:   class Node
  location: class MyList
Main.java:34: error: cannot find symbol
        node.setNext(new Node(value));
                         ^
  symbol:   class Node
  location: class MyList
Main.java:39: error: cannot find symbol
        Node node = head;
        ^
  symbol:   class Node
  location: class MyList
Main.java:53: error: cannot find symbol
        Node node = head;
        ^
  symbol:   class Node
  location: class MyList
8 errors
stdout
Standard output is empty