I am writing a program that accepts names (strings) from a user using node data structures, displays the names, then selectively deletes the names. (I want the input to be in a array). When the names are entered using a for loop and displayed the the program will ask me what I want to delete or what name to remove from the array.
This is my class:
public class Node
{
Node next;
String data;
public Node (String data)
{
this.data = data;
}
}
What the program should do:
Lets say I enter 5 names in a for loop.
Alex, George, Fryon, Storm, Hilbert.
Then when I entered it it will display:
Alex.
George
Fryon
Storm
Hilbert
Then it will ask what name should I delete?
(Alex)
George
Fryon
Storm
Hilbert
But I cant even enter them.
String[] contestant = new String [MAX];
head = null;
for (int i = 0; i <= 5; i++)
{
System.out.println ("Enter a name:");
name [0] = stdin.readLine ();
node = new Node (name [i]);
node.next = head;
head = node;
}
And Im confused if nodes or linked lists relate to arrays. I was hoping to store it as a “node array”, use a for loop to display it “like an array” and then “delete it using sorting like an array”. But its honestly difficult.
Write the following: