Class LinkedList<T>

java.lang.Object
trial.gaurav.collection.LinkedList<T>
Type Parameters:
T - The type of elements stored in the linked list.

public class LinkedList<T> extends Object
A simple implementation of a singly linked list.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Inner class representing a node in the linked list.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private LinkedList<T>.Node<T>
     
    private LinkedList<T>.Node<T>
     
    private LinkedList<T>.Node<T>
     
    private LinkedList<T>.Node<T>
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty linked list.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    contains(Comparator comparator)
    Checks if the linked list contains an element that satisfies the given comparator.
    Retrieves the data from the current node.
    void
    Sets the current node to the first node in the list.
    Gets the first element of the linked list.
    Gets the last element of the linked list.
    boolean
    Checks if there is a next node in the list.
    void
    insert(T value)
    Inserts a new element at the end of the linked list.
    boolean
    Checks if the linked list is empty.
    void
    Sets the current node to the last node in the list.
    void
    Sets the current node to the next node in the list.
    void
    remove(T item)
    Removes the first occurrence of the specified item from the linked list.
    int
    Gets the size of the linked list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • LinkedList

      public LinkedList()
      Constructs an empty linked list.
  • Method Details

    • getFirst

      public T getFirst()
      Gets the first element of the linked list.
      Returns:
      The first element or null if the list is empty.
    • getLast

      public T getLast()
      Gets the last element of the linked list.
      Returns:
      The last element or null if the list is empty.
    • first

      public void first()
      Sets the current node to the first node in the list.
    • last

      public void last()
      Sets the current node to the last node in the list.
    • current

      public T current()
      Retrieves the data from the current node.
      Returns:
      The data value stored in the current node.
    • insert

      public void insert(T value)
      Inserts a new element at the end of the linked list.
      Parameters:
      value - The value to be inserted.
    • size

      public int size()
      Gets the size of the linked list.
      Returns:
      The number of elements in the linked list.
    • isEmpty

      public boolean isEmpty()
      Checks if the linked list is empty.
      Returns:
      True if the linked list is empty, otherwise false.
    • next

      public void next()
      Sets the current node to the next node in the list.
    • hasNext

      public boolean hasNext()
      Checks if there is a next node in the list.
      Returns:
      True if there is a next node, otherwise false.
    • remove

      public void remove(T item)
      Removes the first occurrence of the specified item from the linked list.
      Parameters:
      item - The item to be removed.
    • contains

      public boolean contains(Comparator comparator)
      Checks if the linked list contains an element that satisfies the given comparator.
      Parameters:
      comparator - The comparator to use for the check.
      Returns:
      True if the comparator's condition is met, otherwise false.