Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python . so adding in def pop(self, index) Extending from : class UnorderedList: def __init__(self): self.head = None self.count = 0 def add(self, item):

Using python .

so adding in def pop(self, index)

Extending from :

class UnorderedList: def __init__(self): self.head = None self.count = 0 def add(self, item): new_node = Node(item) new_node.set_next(self.head) self.head = new_node def remove(self, item): current = self.head previous = None while current: if current.get_data() == item: if previous == None: self.head = current.get_next() else: previous.set_next(current.get_next()) return else: previous = current current = current.get_next()

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

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 __str__(self): result = "[" node = self.head while node: result += ('' if result == '[' else ", ") + str(node.data) node = node.next result += "]"

return result def append(self, item): new_node = Node(item) current = self.head if current ==None: self.head = new_node return while current.get_next() !=None: current = current.get_next() current.set_next(new_node)

image text in transcribed

*Extend the UnorderedList class by adding the pop(self, index) method that that takes an integer index as a parameter and removes the item at the index position in the unordered linked list. The index should be in the range [0..length-1]. If the method is called without any parameter, the last element will be removed from the unordered linked list. 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. Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks. For example: Test Result my_list- UnorderedList)3 for x in [3,5,4,6,7,8]: my_list.add(x) print(my_list.pop)) for x in [3,5,4,6,7,8]: my_list.add(x) print(my_list.pop(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

Data And Information Quality Dimensions, Principles And Techniques

Authors: Carlo Batini, Monica Scannapieco

1st Edition

3319241060, 9783319241067

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago