Advertisement
vmeansdev

LinkedList

Sep 11th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class LinkedList
  4. {
  5.     public Node head;
  6.     public Node tail;
  7.  
  8.     public LinkedList()
  9.     {
  10.         head = null;
  11.         tail = null;
  12.     }
  13.  
  14.     public void addInTail(Node item) {
  15.         // write your code here
  16.     }
  17.  
  18.     public Node find(int value) {
  19.         // write your code here
  20.         return null;
  21.     }
  22.  
  23.     public ArrayList<Node> findAll(int value) {
  24.         ArrayList<Node> nodes = new ArrayList<>();
  25.         // write your code here
  26.         return nodes;
  27.     }
  28.  
  29.     public boolean remove(int value) {
  30.         // write your code here
  31.         return false;
  32.     }
  33.  
  34.     public void removeAll(int _value) {
  35.         // write your code here (optional)
  36.     }
  37.  
  38.     public void clear() {
  39.         // write your code here
  40.     }
  41.  
  42.     public int count()
  43.     {
  44.         int count = 0;
  45.         // write your code here
  46.         return count;
  47.     }
  48.  
  49.     public void insertAfter(Node nodeAfter, Node nodeToInsert) {
  50.         // write your code here
  51.     }
  52.  
  53.     @Override
  54.     public String toString() {
  55.         StringBuilder builder = new StringBuilder();
  56.         builder.append("[");
  57.         Node node = this.head;
  58.         while (node != null) {
  59.             String stringVal = this.tail == node ? String.valueOf(node.value) : node.value + ", ";
  60.             builder.append(stringVal);
  61.             node = node.next;
  62.         }
  63.         builder.append("]");
  64.  
  65.         return builder.toString();
  66.     }
  67. }
  68.  
  69. class Node
  70. {
  71.     public int value;
  72.     public Node next;
  73.     public Node(int _value)
  74.     {
  75.         value = _value;
  76.         next = null;
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement