Question: Guidance The starting contents of a data structure includes both its size and item values. The expected output is based on the starting contents of

Guidance The starting contents of a data structure includes both its size and item values. The expected output is based on the starting contents of theArray. I could change the starting contents of theArray when I test your code. You are NOT allowed to hard-code an answer to any part. Your code should work if I change the starting contents of theArray. Part 1 ------ In the starter code, tail should be used to keep track of the last item in the linked structure, as the items are added to the rear one-by-one in a loop. Part 2 ------ Start at head and traverse (loop) through the linked nodes. Print each node's data value as you encounter it. If currentNode is the current node, then use the following to print its data: print(currentNode.data)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# This program exercises arrays and linked lists of nodes.

# Replace any "" comments with your own code statement(s)

# to accomplish the specified task.

# Do not change any other code.

# The following files must be in the same folder:

# arrays.py

# node.py

from arrays import Array

from node import Node

# Here is the array:

theArray = Array(10)

for i in range(len(theArray)):

theArray[i] = i + 1

# Print the array:

print("The array structure:")

print(theArray)

head = Node(theArray[0], None)

tail = head

# Part 1:

# Copy the array items to a linked structure:

# The linked structure must consist of Node class items.

# You must use some form of a loop to create the linked structure.

#

print() # blank line

# Part 2:

print("The linked structure:")

# Print the linked structure with each item on a separate line.

# You must use some form of a loop to print the linked structure.

#

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

output

The array structure: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] The linked structure: 1 2 3 4 5 6 7 8 9 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!