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:

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 10PE
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning