EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 19, Problem 1AW
Explanation of Solution
Recursive method definition for “print”:
The recursive method definition for “print” is given below:
//Define recursive method for "print"
static void print(Node ref)
{
/* If the reference "ref" is not equal to "null", then */
if (ref != null)
{
// Display the first value in the reference
System.out.print(ref.value + " ");
//Recursively call the method "print" with next value of "ref"
print(ref.next);
}
}
Explanation:
From the above method,
- If the reference “ref” is not equal to “null”, then display the first element in the reference.
- And then recursively call the function “print” with the next value of “ref”.
Complete code:
The complete executable code for recursive method “print” is given below:
//Define "Example2LinkedList " class
public class Example2LinkedList
{
//Define recursive method for "print"
static void print(Node ref)
{
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q2
Write the number of point and the letter of the correct answer:
1. The number of fields in the node of double linked list as circular is..............
A. 2
B. 3
C. 4
D. 5
2. Which the following can implement by stack?
A. recursive problems
B. reveres words
C. both a and b
D. None of the above
3. The infix expression for the postfix expression: ab+c/ is:
A. a+b/c
B. (a+b)/c
C. a+(b/c)
D. None of above
4. With queue data structure, The condition last=first indicates that
A. queue is empty
B. queue is full
C. queue has only one element
D. None of the above
choose the correct answer (data
structure in java)
2
10
(0.5X2
Page 1 of 4
A consecutive sequence a list of numbers that are organized in increasing order
with the next eleme. one bigger than the current. Write a non-recursive method
"lengthConsec", which takes an IntNode myList as the parameter and
returns the length of the consecutive sequence in myList. To simplify the
implementation, you can assume that there is no more than one consecutive
sequence in the list.
For example, in the following linked list, the consecutive sequence begins at node "5"
and ends at node "7", so lengthConsec (myList) should return 3 in this case.
myList
8
13
4
public class IntNode
{
12
private int m_data;
private IntNode m_link;
Consecutive sequence
6
7
28
In python. Write a LinkedList class that has recursive implementations of the add and remove methods. It should also have recursive implementations of the contains, insert, and reverse methods. The reverse method should not change the data value each node holds - it must rearrange the order of the nodes in the linked list (by changing the next value each node holds).
It should have a recursive method named to_plain_list that takes no parameters (unless they have default arguments) and returns a regular Python list that has the same values (from the data attribute of the Node objects), in the same order, as the current state of the linked list.
The head data member of the LinkedList class must be private and have a get method defined (named get_head). It should return the first Node in the list (not the value inside it).
As in the iterative LinkedList in the exploration, the data members of the Node class don't have to be private. The reason for that is because Node is a trivial class…
Chapter 19 Solutions
EBK STARTING OUT W/JAVA:...DATA...
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.3 - Prob. 19.4CPCh. 19 - A list is a collection that _____. a. associates...Ch. 19 - Prob. 2MCCh. 19 - Prob. 3MCCh. 19 - Prob. 4MCCh. 19 - Prob. 5MCCh. 19 - Prob. 6MCCh. 19 - Prob. 7MC
Ch. 19 - Prob. 11TFCh. 19 - Prob. 12TFCh. 19 - Prob. 13TFCh. 19 - Prob. 14TFCh. 19 - Prob. 15TFCh. 19 - Prob. 16TFCh. 19 - Prob. 17TFCh. 19 - Prob. 18TFCh. 19 - Prob. 19TFCh. 19 - Prob. 20TFCh. 19 - Prob. 1FTECh. 19 - Prob. 2FTECh. 19 - Prob. 3FTECh. 19 - Prob. 4FTECh. 19 - Prob. 5FTECh. 19 - Prob. 1AWCh. 19 - Prob. 2AWCh. 19 - Prob. 3AWCh. 19 - Prob. 4AWCh. 19 - Prob. 3SACh. 19 - Prob. 4SACh. 19 - Prob. 5SACh. 19 - Consult the online Java documentation and...Ch. 19 - Prob. 1PCCh. 19 - Prob. 2PC
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- This is java recursive code --> I only need this method. please help Write a RECURSIVE method “int sumPos(Node head)” to calculate the sum of positive integers in a linked list of integers referenced by head. No global variables are allowed. Node is declared as: Node { int value; Node next; }arrow_forwardJava language Write a method to insert an array of elements at index in a single linked list and then display this list. The method receives this array by parametersarrow_forward//No need for the whole code //just the methods please for both Write a recursive method “int sumPos(Node head)” to calculate the sum of positive integers in a linked list of integers referenced by head. No global variables are allowed. Node is declared as: Node { int value; Node next; } Write a non-recursive method “int sumPos(Node head)” to calculate the sum of positive integers in a linked list of integers referenced by head. No global variables are allowed. Node is declared as: Node { int value; Node next; }arrow_forward
- public int numdescendantsmod(int y) without recursion. this m O ethod should return the number of nodes that have a value tha Remove t is 0 mod y.arrow_forwardhelp with this function C++ Write a recursive method, to be included in an unsorted linked list class, called greater, that will receive an x parameter. The method will print the info of nodes that contain a value that is greater than theparameter.arrow_forwardWrite a recursive instance method isSorted that takes a Link parameter and determines whether a linked list is sorted in descending order or not (return a boolean value).arrow_forward
- Please give me the proper answer with step by step solution Qns:Java question Implement a method that adds a value in a linked list using recursion and using this signature: public void addValue(int value)arrow_forwardWhat the code is about: Implement a recursive algorithm to add all the elements of a non-dummy headed singly linked linear list. Only head of the list will be given as parameter where you may assume every node can contain only integer as its element.Note: you’ll need a Singly Node class for this code. **PLEASE EXPLAIN HOW THE NODE CLASS AND THE CONSTRUCTOR OF THE NODE CLASS IS WORKING IN THIS CODE** #singlty node class for single linked listclass node: def __init__(self, value = None, next=None): self.value = value self.next = nextdef AddAll(head):#takes head of single linked list head if head==None: return 0#if reached end of the linked list return AddAll(head.next) + head.value #each node's next pointer is passed in recursive call #and value of each node is added while returning from recursive callarrow_forwarda. Write the recursive method for adding a node in a linked list. b. Consider the infix expression 15 + 2 – 10 / 2 ∗ 2 and convert this into postfix expression using stack. Next Token Action Effect on operatorStack Effect on postfix 15 + 2 - 10 / 2 * 2arrow_forward
- Java help, can you please explain this I'm a beginner and I'm lost:( Implement a nested class DoubleNode for building doubly-linked lists, where each node containsa reference to the item preceding it and the item following it in the list (null if there is no suchitem). Then implement methods for the following tasks:• Print the contents of the list• Insert at the beginning• Insert at the end• Remove from the beginning• Remove from the end• Insert before a give node (Insert before the first occurrence of the node, if thenode exists; else insert at the end)• Insert after a given node (Insert after the first occurrence of the node, if the nodeexists; else insert at the end)• Remove a given node (Remove the first occurrence of the node, remove nothing ifnode not found)• Move to front (move the first occurrence of the node to the front)• Move to end (moved and first occurrence of the node to the end)Write a tester program and test your implementation. You must test each of these cases…arrow_forwardGiven a singly linked list, print reverse of it using a recursive function printLinkedList( node *first ) where first is the pointer pointing to the first data node. For example, if the given linked list is 1->2->3->4, then output should be: 4 3 2 1 (note the whitespace in between each data value)arrow_forwardImplement the following two methods in O(n) time. // Reverse the list and return it in O(n) time public static <E> ArrayList<E> reverse(ArrayList<E> list) // Reverse the list and return it in O(n) time public static <E> LinkedList<E> reverse(LinkedList<E> list) Use the following code to test these methods: public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter 10 numbers: "); ArrayList<Integer> list = new ArrayList<>(); for (int i = 0; i < 10; i++) { list.add(input.nextInt()); } reverse(list); for (int i: list) { System.out.print(i + " "); } System.out.println(); LinkedList<Integer> list1 = new LinkedList<>(list); reverse(list1); for (int i: list1) { System.out.print(i + " "); } System.out.println(); }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education