Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

code used:

python

 

class Node:
    def __init__(self, value):
        self.data_val = value
        self.next_node = None

    def insert_after(self, node):
        tmp_node = self.next_node
        self.next_node = node
        node.next_node = tmp_node

    def get_next(self):
        return self.next_node

    def print_data(self):
        print(self.data_val, end=", ")

# TODO: Write recursive print_list() function here.

        
if __name__ == "__main__":
    size = int(input())
    value = int(input())
    head_node = Node(value) # Make head node as the first node
    last_node = head_node
    
    # Insert the second and the rest of the nodes
    for n in range(1, size):
        value = int(input())
        new_node = Node(value)
        last_node.insert_after(new_node)
        last_node = new_node
    
    print_list(head_node)

Write a recursive function called print_list() that outputs the integer value of each node in a linked list. Function print_list() has one
parameter, the head node of a list. The main program reads the size of the linked list, followed by the values in the list. Assume the linked
list has at least 1 node.
Ex: If the input of the program is:
5
1.
2
3
4
5
the output of the print_list() function is:
1, 2, 3, 4, 5,
Hint: Output the value of the current node, then call the print_list() function repeatedly until the end of the list is reached. Refer to the Node
class to explore any available instance methods that can be used for implementing the print_list() function.
expand button
Transcribed Image Text:Write a recursive function called print_list() that outputs the integer value of each node in a linked list. Function print_list() has one parameter, the head node of a list. The main program reads the size of the linked list, followed by the values in the list. Assume the linked list has at least 1 node. Ex: If the input of the program is: 5 1. 2 3 4 5 the output of the print_list() function is: 1, 2, 3, 4, 5, Hint: Output the value of the current node, then call the print_list() function repeatedly until the end of the list is reached. Refer to the Node class to explore any available instance methods that can be used for implementing the print_list() function.
Expert Solution
Check Mark
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
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

Expert Answers to Latest Homework Questions

Q: Can you explain the correct approach to solve this general accounting question?
Q: Please provide the answer to this general accounting question using the right approach.
Q: Find
Q: Can you help me solve this general accounting question using the correct accounting procedures?
Q: Please help me solve this general accounting problem with the correct financial process.
Q: This has to be done advanced mathematics report , also give the code for this. And do not give…
Q: Subject. GENERAL ACCOUNT QUESTIONS
Q: Can you help me solve this general accounting problem with the correct methodology?
Q: I need help solving this general accounting question with the proper methodology.
Q: Subject = General Account
Q: 1.0 Half-power point (left) 0.5 Minor lobes Main lobe maximum direction Main lobe Half-power point…
Q: Accounting?
Q: Driftwood Furniture Company implemented a new quality control system. Product approval requires:…
Q: I am trying to find the accurate solution to this general accounting problem with appropriate…
Q: Can you help me solve this general accounting problem with the correct methodology?
Q: Can you help me solve this general accounting problem with the correct methodology?
Q: The US involvement in the Israeli Syrian negotiations was impeded by: lacking history of supporting…
Q: general accounting
Q: I am searching for the accurate solution to this general accounting problem with the right approach.
Q: I need help solving this general accounting question with the proper methodology.
Q: Can you help me solve this general accounting problem with the correct methodology?