• Ask the user to enter a set of 5 numbers.
• For each number entered, add it into the front of the linked list.
• Now, ask the user to enter a search number.
• Using a for loop or while loop, search whether the number exist in one of the Nodes in the linked list.
• If there is a matching node, create a new node with data 88 and insert it right before the matching node. Otherwise, display the message “No such number”.
Hi everyone, I would like you to help me with the java code for the last part.
public static void main(String[] args) {
LinkedList list = new LinkedList();
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number: ");
int num = sc.nextInt(); sc.nextLine();
for(int i = 0; i < 4; i++){
list.addFront(num);
}
System.out.print("Enter a number: ");
int search = sc.nextInt(); sc.nextLine();
for(Node j = list.getHead(); j!= null; j=j.getNext()){
if((Integer)j.getData()==search){
list.addNode();
}else{
System.out.println("No such number");
}
}
public static Node addNode(T n);//???
}