Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA !!!! Write the following classes that implement a single Linked List of integers. Class Node: It includes two instance variables: int number and

image text in transcribedIN JAVA !!!!
Write the following classes that implement a single Linked List of integers. Class Node: It includes two instance variables: int number and Node next It contains the following methods: A constructor that initializes the instance variable number. Set and get method for each instance variable. Class singleLinkedList: It includes two instance variables: Node head and Node. It contains the following methods: public void insert (int n) that creates and adds a Node at the end of the linked List. public void print () that prints the values of all nodes in the liked list, separated by an arrow (rightarrow), as shown in the sample output. public boolean oneDigit ()that returns true if all nodes in the linked List have a one-digit value and false otherwise. public void iterativeReverse () that reverses the original linked list iteratively. public void recursiveReverse () that calls the private method void recursiveReverse(Node head) private void recursiveReverse (Node current) that reverses the original linked list recursively. Class TestSingleLinkedList In the main method, do the following: Create an object of class singleLinkedList Read integer values from the user. The user must enter -1 to stop Call method print() Call method one Digit() and print a proper message based on the returning value. Call method recursiveReverse() and then call method print() Call method iterativeReverse() and then call method print() Sample output 1: Enter integer values or -1 to stop: 5 2 4 6 7-1 5 rightarrow 2 rightarrow 4 rightarrow 6 rightarrow 7 All values in LinkedList are one-digit integers Reversing the LinkedList using recursive method: 7 rightarrow 6 rightarrow 4 rightarrow 2 rightarrow 5 Reversing the LinkedList again using iterative method: Sample output 2. Enter integer values or -1 to stop: 10 7 3 2 4 -1 10 rightarrow 7 rightarrow 3 rightarrow 2 rightarrow 4 Not all values in LinkedList are one-digit integers Reversing the LinkedList using recursive method: 4 rightarrow 2 rightarrow 3 rightarrow 7 rightarrow 18 Reversing the LinkedList again using iterative method: 10 rightarrow 7 rightarrow 3 rightarrow 2 rightarrow 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions