Page 1 of 1

In a Link list how do I 1.write a method that returns nth element in the list 2.Search for a specific value in a list 3.

Posted: Sat May 14, 2022 7:48 pm
by answerhappygod
In a Link list how do I
1.write a method that returns nth element in the list
2.Search for a specific value in a list
3.Insert an element in front of the list
4. Remove an element by value
These my code so far
public class LinkList_A {
Node head; //---->Creating a variable that
is head which is a reference



public class Node{ ////---->Creating the node
class

int data ; //creating a
variable

Node next; //Creating
anaother variable, Node is just link to the next node,

Node(int d) // a node is just
what ever data we give it
{

data =
d; //the data becomes becomes what ever "d" value is

next =
null; //.next is null at the begining because there is nothing
pointing at it


//because the list is empty

}

}
public void push(int newData) {

Node newNode = new
Node(newData);

newNode.next = head;
newNode = head;

}
public int getItem(int number) {

}