ica

.pdf

School

Arizona State University *

*We aren’t endorsed by this school

Course

MISC

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

4

Uploaded by ProfessorOysterMaster1078

Report
1. CSC 120 Work with your neighbor. (This will be graded for participation only.) ICA-13 For reference, here are diagrams of a Python list and a LinkedLi st having the integers 10,20 and 30 as elements: alist S 10 ahst\‘ I:I\A 10 30 20 30 None The LinkedList code includes a method add () for adding to the front of a LinkedList: class Node: def 1nit (self, value): self. value = value self. next = None class LinkedlList: def init (se self. head def add(self, new. next = self. head 1f) : = None new) : self. head = new Draw a diagram that shows the linked list alist and the node n after the statements below are executed: >>> glist = >>> n = Node (1l4) LinkedList () Draw a diagram that shows the list alist after the statement below is executed: >>> alist.add(n) Draw a diagram that shows the node n after the statement below 1s executed: >>> n = Node (0)
Draw a diagram that shows the list alist after the statement below is executed: >>> alist.add(n) Note: You may draw the diagram without the box for the list head and without labelling the last node’s next reference with None. 2. This code has a method for traversing a LinkedList to print all node values. class Node: def init (self, value): self. value = value self. next = None class LinkedList: def init (self): self. head = None def add(self, new): new. next = self. head self. head = new def print elements(self): current = self. head while current != None: print (str(current. value)) current = current. next Using the LinkedList and Node class definitions above, write a method double () for the LinkedList class that doubles the value attributes of all nodes in a LinkedList. You may assume that for each node in the list, the value attribute is an integer. 3. The code in problem 2 has a method print elements (self) for traversing a LinkedList to print all node values. Let’s go through the steps to do that for the linked list below:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help