Question: I am looking for Mk_Shiva32 for help with this problem, as this user was the only one to follow the correct formar in t previous

I am looking for Mk_Shiva32 for help with this problem, as this user was the only one to follow the correct formar in t previous question I had asked.

further below is the actual problem.

*For the entirety of this question you are not allowed to use any data structure * other than a custom built linked list. This should consist ONLY of a node * class that will be given. You should not be creating a secondary class to handle the data * structure. * * Failure to do so will result in no credit.

the node class

public class Node { private E item; private Node next;

public Node(E item, Node next) { //0, null this.item = item; this.next = next; }

public E getItem() { return item; }

public void setItem(E item) { this.item = item; }

public Node getNext() { return next; }

public void setNext(Node next) { this.next = next; }

}

the problem: THIS IS WHERE I AM STUCK, PLEASE READ THE PROBLEM.

/** * Problem: Using the Linked List from problem A (PROBLEM A IS BELOW THIS CODE) , print the contents of the Linked List in ascending order, UNLESS the list contains the number 5. If it * contains the number 5, print the list in descending order. DO NOT MAKE ANY OTHER METHODS OR CLASSES AND DO NOT CHANGE ANY OF THE METHOD HEADERS OR CLASSES

public Node sortIntegers(Node linkedList) { return null; // Return the start node of your linked list as well as printing it. The "null" can be changed to //"start" }

PROBLEM A:

public Node addInts() { Scanner userInput = new Scanner(System.in);

Node start, tail = new Node<>(0, null); start = null; System.out.println("Enter numbers and enter STOP to finish"); while(true) {

if(userInput.hasNextInt()) { int numInput = userInput.nextInt(); if (start == null) { start = new Node<>(numInput, null); tail = start; } else { Node next = new Node<>(numInput, null); tail.setNext(next); tail = tail.getNext(); } } else if(userInput.hasNext("STOP") || userInput.hasNext("stop")) { break; } else { userInput.next(); System.out.println("Not a valid input, please enter another integer or type STOP to print off linked list."); } } Node p = start; while (p != null) { System.out.print(p.getItem()); if (p.getNext() != null) System.out.print(", "); p = p.getNext(); } System.out.println(); return start; }

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 Programming Questions!