Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Node: def __init__(self, init_data): self.data = init_data self.next = None def get_data(self): return self.data def get_next(self): return self.next def set_data(self, new_data): self.data = new_data

class Node: def __init__(self, init_data): self.data = init_data self.next = None

def get_data(self): return self.data

def get_next(self): return self.next

def set_data(self, new_data): self.data = new_data

def set_next(self, new_next): self.next = new_next

class LinkedListIterator: def __init__( self, head): self.current = head

def __next__( self ): if self.current != None: item = self.current.get_data() self.current = self.current.get_next() return item else : raise StopIteration class UnOrderedList: def __init__(self): self.head = None

def is_empty(self): return self.head == None

def size(self): curr = self.head count = 0 while curr != None: count = count + 1 curr = curr.get_next() return count def add(self, item): new_node = Node(item) new_node.set_next(self.head) self.head = new_node

def search(self,item): current = self.head while current != None: if current.get_data() == item: return True else: current = current.get_next() return False

def remove(self,item): current = self.head previous = None found = False while not found: if current.get_data() == item: found = True else: previous = current current = current.get_next()

if previous == None: self.head = current.get_next() else: previous.set_next(current.get_next())

def __iter__(self): return LinkedListIterator(self.head)

image text in transcribed

Extend the UnorderedList class by adding the get(self, index) method that takes an integer index as a parameter and returns the data value stored in the node at that index position in a unordered linked list. The index should be in the range [0..length-1] The implementations of the Node is provided to you as part of this exercise. You can simply use: Node(), get_next), set_next(), as well as get_data() and set_data) as necessary in your function definition. Note: You should include the entire UnorderedList class definition in your answer to this question. For example Test Result my_list - UnorderedList) 7 for x in [3,5,4,6,7,8] my_list.add(x) print (my_list.get(1)) my_list - UnorderedList) 8 for x in [3,5,4,6,7,8]: my_list.add(x) print(my_list.get (0)) Extend the UnorderedList class by adding the get(self, index) method that takes an integer index as a parameter and returns the data value stored in the node at that index position in a unordered linked list. The index should be in the range [0..length-1] The implementations of the Node is provided to you as part of this exercise. You can simply use: Node(), get_next), set_next(), as well as get_data() and set_data) as necessary in your function definition. Note: You should include the entire UnorderedList class definition in your answer to this question. For example Test Result my_list - UnorderedList) 7 for x in [3,5,4,6,7,8] my_list.add(x) print (my_list.get(1)) my_list - UnorderedList) 8 for x in [3,5,4,6,7,8]: my_list.add(x) print(my_list.get (0))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Semantics In Databases Second International Workshop Dagstuhl Castle Germany January 2001 Revised Papers Lncs 2582

Authors: Leopoldo Bertossi ,Gyula O.H. Katona ,Klaus-Dieter Schewe ,Bernhard Thalheim

2003rd Edition

3540009574, 978-3540009573

More Books

Students also viewed these Databases questions

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago

Question

LO1 Understand risk management and identify its components.

Answered: 1 week ago