Question: HELP IN JAVA: Input is from the keyboard. Input integers, you don't know how many but the last one will be zero. Put these integers

HELP IN JAVA: Input is from the keyboard. Input integers, you don't know how many but the last one will be zero. Put these integers into a list called list1 (not sorted, just put each new one at the end of the list. ) When you have finished creating your list, print it. Then create two new lists, one to hold all the even integers, one for the odds. Go through your original list deleting a node and adding it to either the odd or even list. Print out all three lists (the original one should now be empty).

MAke sure not to use ArrayList and only use LinkedList with Nodes.

Prompted the user for input

Used nodes and NOT a built in class

Input from keyboard terminating in 0

Deleted nodes from first list

Added correctly to other lists

Printed out all three lists

HERE IS WHAT I HAVE SO FAR:

Here is the Node.java:

public class Node { Object item; Node next; Node(Object newItem) { item = newItem; next=null; } Node(Object newItem, Node nextNode) { item = newItem; next=nextNode; } }

public class H3a {

public static Node ListInsertAfter(Node head, Node curNode, Node newNode, Node tail) { if (head == null) { // List empty head = newNode; tail = newNode; } else if (curNode == tail) { // Insert after tail tail.next = newNode; tail = newNode; } else { newNode.next = curNode.next; curNode.next = newNode; } return head; }

public static void printList(Node head) { Node curr=head; while (curr !=null) {System.out.println(curr.item); curr=curr.next; } } public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); int check; Node head=null; Node curr = null; System.out.println("Please enter a number, enter 0 to quit"); check = keyboard.nextInt(); while(check != 0) { curr = new Node(check); curr.next=head; head = curr; System.out.println("Please enter a number, enter 0 to quit"); check = keyboard.nextInt(); } System.out.println(" Original List:"); printList(head); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!