Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
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)

    {

Blurred answer
Students have asked these similar questions
//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; }
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
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; }
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education