Package OOPJ_MP
Class LinkedList
java.lang.Object
OOPJ_MP.LinkedList
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
FieldsModifier and TypeFieldDescriptionstatic final int
This variable show the Position at where you want to add the nodestatic final int
This variable show the Position at where you want to add the nodestatic final int
This variable show the Position at where you want to add the nodestatic final int
This variable show the Position at where you want to add the nodeint
This shows the length of the node available in theLinkedList
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
This is methid that insert the node at beginning or at endint
This method used to insert the node to Before a Node Or After a Nodeint
When you want to insert a Node in a specific Index then this method is usediterator()
ThisLinkedList
class is iterable so to iterate this class using for each loop this is the iterator methodnodeAt
(int Index) This method returns the Node which is at given Index Without removing it from listpop
(int Position) This method pop an element for given Position ie.This method pop an element in respect to another node like pop: node before a node or pop node after the nodepopNodeAt
(int Index) This Method POP an element from list with given index The element is pop from list alsoint
searchElement
(Node Search_Node) This method search the node is available inLinkedList
or not if available then it returns the index of node in which the node is presentNode[]
toArray()
This method return aNode
array Containing all the element ofLinkedList
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 lengthThis shows the length of the node available in theLinkedList
-
BEGINNING
public static final int BEGINNINGThis variable show the Position at where you want to add the node- See Also:
-
BEFORE
public static final int BEFOREThis variable show the Position at where you want to add the node- See Also:
-
AFTER
public static final int AFTERThis variable show the Position at where you want to add the node- See Also:
-
END
public static final int ENDThis variable show the Position at where you want to add the node- See Also:
-
-
Constructor Details
-
LinkedList
public LinkedList()default constructor
-
-
Method Details
-
insertAt
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 nodeNew_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 throwsIndexOutOfBoundsException
-
insert
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 useLinkedList
.BEGINNING
OREND
for this parameterNew_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 generateIndexOutOfBoundsException
-
insert
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 useLinkedList
.BEFORE
ORAFTER
for this parameterSearch_Node
- This is the node where you want to insert the node like before this Search_Node or After the Search_nodeNew_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 theNodeNotFoundException
-
popNodeAt
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 theIndexOutOfBoundsException
EmptyLinkedListException
- if the List is empty then it throws theEmptyLinkedListException
-
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 fromLinkedList
.BEFORE
ORAFTER
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 theEmptyLinkedListException
NodeNotFoundException
- if the given Search Node in not found in the List then it throwsNodeNotFoundException
-
pop
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 fromLinkedList
.BEGINNING
OREND
- Returns:
- the element which is removed
- Throws:
EmptyLinkedListException
- if the List is empty then it throws theEmptyLinkedListException
-
nodeAt
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
This method search the node is available inLinkedList
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 theLinkedList
- Returns:
- it the Index in which the Node is occurring
- Throws:
NodeNotFoundException
- if the given node is not found in theLinkedList
then it throwsNodeNotFoundException
-
toArray
This method return aNode
array Containing all the element ofLinkedList
- Returns:
- the array of
Node
class
-
iterator
ThisLinkedList
class is iterable so to iterate this class using for each loop this is the iterator method
-