Question: 1 . Given the codes below, add code to prompt the user to enter how many new names they wish to add to the ArrayList
Given the codes below, add code to prompt the user to enter how many new names they wish to add to the ArrayList object and add it to the list. Display the updated list and its updated size to the console. CustomLinkedList.java Example code to add multiple nodes to a singly linked list
public class CustomLinkedList
public static void mainString args
IntNode headObj; Create IntNode reference variables
IntNode currObj; tmpptr traverses the list
IntNode node; new node to add the linked list
write code to add random numbers between and to
the linked list
int counter ;
step : set the first node in the list
headObj new IntNodeintMathrandom;
step : set tmpptr to the first node
currObj headObj;
until the tmpptr is null
whilecurrObj null && counter
build the node structure
node new IntNodeintMathrandom;
connect the node to the list
is there no list?
ifheadObjgetNext null
headObj.insertAfternode;
else is there a list?
currObj currObj.getNext;
currObj.insertAfternode;
counter; update counter
Print linked list
currObj headObj;
while currObj null
currObj.printNodeData;
currObj currObj.getNext;
public class IntNode
private int dataVal;
Node data
private IntNode nextNodeRef;
Reference to the next node
public IntNode
dataVal ;
nextNodeRef null;
Constructor
public IntNodeint dataInit
this.dataVal dataInit;
this.nextNodeRef null;
Insert node after this node. Before: this next After: this node next
public void insertAfterIntNode nodeLoc
IntNode tmpNext;
tmpNext this.nextNodeRef;
this.nextNodeRef nodeLoc;
nodeLoc.nextNodeRef tmpNext;
Get location of nextNodeRef
public IntNode getNext
return this.nextNodeRef;
public void printNodeData
System.out.printlnthisdataVal;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
