This exercise asks you to define some functions for manipulating linked structures. You should use the Node and TwoWayNode classes, as defined in this chapter. Create a tester module in the testnode.py file that contains your function definitions and your code for testing them. In the testnode.py file, complete the following: Complete the implementation of the length() function (not len). This function expects a singly linked structure as an argument. Returns the number of items in the structure. To test your program run the main() method in the testnode.py file. Your program's output should look like the following:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

This exercise asks you to define some functions for manipulating linked structures. You should use the Node and TwoWayNode classes, as defined in this chapter.

Create a tester module in the testnode.py file that contains your function definitions and your code for testing them.

In the testnode.py file, complete the following:

  1. Complete the implementation of the length() function (not len).
    • This function expects a singly linked structure as an argument.
    • Returns the number of items in the structure.

To test your program run the main() method in the testnode.py file.

Your program's output should look like the following:

0: 0 5: 5

3
bil
/>
Instructions
This exercise asks you to define some
functions for manipulating linked
structures. You should use the Node
and TwoWayNode classes, as defined in
this chapter.
Create a tester module in the testnode.py
file that contains your function definitions
and your code for testing them.
In the testnode.py file, complete the
following:
1. Complete the implementation of the
length() function (not len).
o This function expects a singly
linked structure as an argument.
H
node.py
1
2 File: node.py
3
|| || ||
testnode.py
4 Node classes for one-way linked structures and two-way
5 linked structures.ngular Snip
6 """
7
8 class Node(object):
9
10
11
12
13
14
15 class TwoWayNode (Node):
16
def __init__(self, data, next = None):
"""Instantiates a Node with default next of No
+
self.data data
self.next = next
17
18
19
20
21 # Just an empty link
22 node1 = None
def __init__(self, data, previous = None, next =
Node. __init__(self, data, next)
self.previous = previous
>_ Terminal
sandbox $
X
+
Transcribed Image Text:3 bil /> Instructions This exercise asks you to define some functions for manipulating linked structures. You should use the Node and TwoWayNode classes, as defined in this chapter. Create a tester module in the testnode.py file that contains your function definitions and your code for testing them. In the testnode.py file, complete the following: 1. Complete the implementation of the length() function (not len). o This function expects a singly linked structure as an argument. H node.py 1 2 File: node.py 3 || || || testnode.py 4 Node classes for one-way linked structures and two-way 5 linked structures.ngular Snip 6 """ 7 8 class Node(object): 9 10 11 12 13 14 15 class TwoWayNode (Node): 16 def __init__(self, data, next = None): """Instantiates a Node with default next of No + self.data data self.next = next 17 18 19 20 21 # Just an empty link 22 node1 = None def __init__(self, data, previous = None, next = Node. __init__(self, data, next) self.previous = previous >_ Terminal sandbox $ X +
Instructions
This exercise asks you to define some
functions for manipulating linked
structures. You should use the Node
and TwoWayNode classes, as defined in
this chapter.
Create a tester module in the testnode.py
file that contains your function definitions
and your code for testing them.
In the testnode.py file, complete the
following:
1. Complete the implementation of the
length() function (not len).
o This function expects a singly
linked structure as an argument.
Roturns the number of items in
node.py
testnode.py
9
10 from node import Node
11
12 def length(head):
13
14
15
16
"""Returns the number of items in the linked struc
referred to by head. ""
# Write your code here
17
18 def main():
19
20
21
22
23
24
25
26
27
28
29 if __name__ == "__main__": main()
30
"""Tests modifications."""
head None
print("0:", length(head))
+
# Add five nodes to the beginning of the linked st
for count in range(1, 6):
head = Node (count, head)
print("5:", length(head))
>_ Terminal
sandbox $
x
X
+
Transcribed Image Text:Instructions This exercise asks you to define some functions for manipulating linked structures. You should use the Node and TwoWayNode classes, as defined in this chapter. Create a tester module in the testnode.py file that contains your function definitions and your code for testing them. In the testnode.py file, complete the following: 1. Complete the implementation of the length() function (not len). o This function expects a singly linked structure as an argument. Roturns the number of items in node.py testnode.py 9 10 from node import Node 11 12 def length(head): 13 14 15 16 """Returns the number of items in the linked struc referred to by head. "" # Write your code here 17 18 def main(): 19 20 21 22 23 24 25 26 27 28 29 if __name__ == "__main__": main() 30 """Tests modifications.""" head None print("0:", length(head)) + # Add five nodes to the beginning of the linked st for count in range(1, 6): head = Node (count, head) print("5:", length(head)) >_ Terminal sandbox $ x X +
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Linked List
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
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education