Package OOPJ_MP

Class LinkedList

java.lang.Object
OOPJ_MP.LinkedList
All Implemented Interfaces:
Iterable<Node>

public class LinkedList extends Object implements Iterable<Node>
This is a class to make a list with Dynamic data type you can store any type of data together in this list You need to make an instance of OOPJ_MP.Node class and this element is inserted in this class
Since:
2024
Author:
Mohit MakwanaNeha Kavaiya
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    This variable show the Position at where you want to add the node
    static final int
    This variable show the Position at where you want to add the node
    static final int
    This variable show the Position at where you want to add the node
    static final int
    This variable show the Position at where you want to add the node
    int
    This shows the length of the node available in the LinkedList
  • Constructor Summary

    Constructors
    Constructor
    Description
    default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    insert(int Position, Node New_Node)
    This is methid that insert the node at beginning or at end
    int
    insert(int Position, Node Search_Node, Node New_Node)
    This method used to insert the node to Before a Node Or After a Node
    int
    insertAt(int Index, Node New_Node)
    When you want to insert a Node in a specific Index then this method is used
    This LinkedList class is iterable so to iterate this class using for each loop this is the iterator method
    nodeAt(int Index)
    This method returns the Node which is at given Index Without removing it from list
    pop(int Position)
    This method pop an element for given Position ie.
    pop(int Position, Node Search_Node)
    This method pop an element in respect to another node like pop: node before a node or pop node after the node
    popNodeAt(int Index)
    This Method POP an element from list with given index The element is pop from list also
    int
    searchElement(Node Search_Node)
    This method search the node is available in LinkedList or not if available then it returns the index of node in which the node is present
    This method return a Node array Containing all the element of LinkedList

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Field Details

    • length

      public int length
      This shows the length of the node available in the LinkedList
    • BEGINNING

      public static final int BEGINNING
      This variable show the Position at where you want to add the node
      See Also:
    • BEFORE

      public static final int BEFORE
      This variable show the Position at where you want to add the node
      See Also:
    • AFTER

      public static final int AFTER
      This variable show the Position at where you want to add the node
      See Also:
    • END

      public static final int END
      This variable show the Position at where you want to add the node
      See Also:
  • Constructor Details

    • LinkedList

      public LinkedList()
      default constructor
  • Method Details

    • insertAt

      public int insertAt(int Index, Node New_Node) throws IndexOutOfBoundsException
      When you want to insert a Node in a specific Index then this method is used
      Parameters:
      Index - In which Index you want to insert the node
      New_Node - New Node that inserted in the LinkedList
      Returns:
      Index where the node is inserted
      Throws:
      IndexOutOfBoundsException - When you enter an Invalid index then it throws IndexOutOfBoundsException
    • insert

      public int insert(int Position, Node New_Node) throws IndexOutOfBoundsException
      This is methid that insert the node at beginning or at end
      Parameters:
      Position - This is the Position in which you want to add the Node Note: you should use LinkedList.BEGINNING OR END for this parameter
      New_Node - This is the new Node Instance of OOPJ_MP.Node class and this is element that inserted in the LinkedList
      Returns:
      Index at which the node is inserted
      Throws:
      IndexOutOfBoundsException - if you provide Wrong Position then the method generate IndexOutOfBoundsException
    • insert

      public int insert(int Position, Node Search_Node, Node New_Node) throws NodeNotFoundException
      This method used to insert the node to Before a Node Or After a Node
      Parameters:
      Position - This is the Position in which you want to add the Node Note: you should use LinkedList.BEFORE OR AFTER for this parameter
      Search_Node - This is the node where you want to insert the node like before this Search_Node or After the Search_node
      New_Node - This is the new Node Instance of OOPJ_MP.Node class and this is element that inserted in the LinkedList
      Returns:
      Index at which the node is inserted
      Throws:
      NodeNotFoundException - if your given Search_Node doesn't found in the list then it throws the NodeNotFoundException
    • popNodeAt

      public Node popNodeAt(int Index) throws IndexOutOfBoundsException, EmptyLinkedListException
      This Method POP an element from list with given index The element is pop from list also
      Parameters:
      Index - this is used to specify at which index you want to remove the node
      Returns:
      the node which just you pop
      Throws:
      IndexOutOfBoundsException - if the given index is not valid then it throws the IndexOutOfBoundsException
      EmptyLinkedListException - if the List is empty then it throws the EmptyLinkedListException
    • pop

      public Node pop(int Position, Node Search_Node) throws EmptyLinkedListException, NodeNotFoundException
      This method pop an element in respect to another node like pop: node before a node or pop node after the node
      Parameters:
      Position - This is the Position in which you want to pop the node this parameter should pass from LinkedList.BEFORE OR AFTER
      Search_Node - This is the refrence Node in which respect you want to remove the node This should be OOPJ_MP.Node class instance
      Returns:
      the element which is removed
      Throws:
      EmptyLinkedListException - if the List is empty then it throws the EmptyLinkedListException
      NodeNotFoundException - if the given Search Node in not found in the List then it throws NodeNotFoundException
    • pop

      public Node pop(int Position) throws EmptyLinkedListException
      This method pop an element for given Position ie. pop first element from list of pop last element from list
      Parameters:
      Position - This is the Position in which you want to pop the node this parameter should pass from LinkedList.BEGINNING OR END
      Returns:
      the element which is removed
      Throws:
      EmptyLinkedListException - if the List is empty then it throws the EmptyLinkedListException
    • nodeAt

      public Node nodeAt(int Index)
      This method returns the Node which is at given Index Without removing it from list
      Parameters:
      Index - you shold specify the index at which you want to access the Node
      Returns:
      the Node that occur at given Index
    • searchElement

      public int searchElement(Node Search_Node) throws NodeNotFoundException
      This method search the node is available in LinkedList or not if available then it returns the index of node in which the node is present
      Parameters:
      Search_Node - This is the Node which you want to search in the LinkedList
      Returns:
      it the Index in which the Node is occurring
      Throws:
      NodeNotFoundException - if the given node is not found in the LinkedList then it throws NodeNotFoundException
    • toArray

      public Node[] toArray()
      This method return a Node array Containing all the element of LinkedList
      Returns:
      the array of Node class
    • iterator

      public Iterator<Node> iterator()
      This LinkedList class is iterable so to iterate this class using for each loop this is the iterator method
      Specified by:
      iterator in interface Iterable<Node>
      Returns:
      returns the Iterator<Node>