Below is the initial code for linked list implementation of dictionary ADT. Complete the code for the following functions: • def remove_item(self, key): • def remove_all_items(self, key): • def find_item(self, key): def find_all_items(self, key):

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Use python code, carefully read the instructions.

Below is the initial code for linked list implementation of dictionary ADT. Complete the code for
the following functions:
• def remove_item(self, key):
def remove_all_items(self, key):
• def find_item(self, key):
def find_all_items(self, key):
PAGE 1
PAGE 2
def insert_item(self, key, item):
new_node = Node(key, item)
import os
class Node:
if self.head is None:
def _init_(self, key = None, value = None):
self.key = key
self.head = new_node
return
self.value = value
self.next = None
last = self.head
while (last.next):
def
str_(self):
last = last.next
return "{}\n".format(self.data)
last.next = new_node
class Dictionary:
#def remove_item(self, key):
def _init_(self):
self.head = None
#def remove_all_items(self, key):
def _str_(self):
string = "{"
ptr = self.head
while ptr.next != None:
string += "({},{}),".format(ptr.key, ptr.value)
ptr = ptr.next
string += "({},{})".format(ptr.key, ptr.value)
return string + "}"
#def find_item(self, key):
#def find_all_items(self, key):
dictionary = Dictionary(5)
dictionary.insert_item(1, 2)
dictionary.insert_item(2, 6)
dictionary.insert_item(3, 9)
dictionary.insert_item(1, 10)
print(dictionary)
print(dictionary.find_item(3))
print(dictionary.find_item(1))
print(dictionary.find_all_items(1))
dictionary.remove_item(2)
print(dictionary)
dictionary.remove_all_items(1)
print(dictionary)
def empty(self):
return self.head == None
def dictionary_size(self):
count = 0
self.ptr = self.head
while self.ptr != None:
count = count + 1
self.ptr = self.ptr.next
return count
Sample Run
{ (1,2),(2,6),(3,9),(1,10) }
9
2
[2, 10]
{ (1,2),(3,9),(1,10)}
{ (3,9) }
Transcribed Image Text:Below is the initial code for linked list implementation of dictionary ADT. Complete the code for the following functions: • def remove_item(self, key): def remove_all_items(self, key): • def find_item(self, key): def find_all_items(self, key): PAGE 1 PAGE 2 def insert_item(self, key, item): new_node = Node(key, item) import os class Node: if self.head is None: def _init_(self, key = None, value = None): self.key = key self.head = new_node return self.value = value self.next = None last = self.head while (last.next): def str_(self): last = last.next return "{}\n".format(self.data) last.next = new_node class Dictionary: #def remove_item(self, key): def _init_(self): self.head = None #def remove_all_items(self, key): def _str_(self): string = "{" ptr = self.head while ptr.next != None: string += "({},{}),".format(ptr.key, ptr.value) ptr = ptr.next string += "({},{})".format(ptr.key, ptr.value) return string + "}" #def find_item(self, key): #def find_all_items(self, key): dictionary = Dictionary(5) dictionary.insert_item(1, 2) dictionary.insert_item(2, 6) dictionary.insert_item(3, 9) dictionary.insert_item(1, 10) print(dictionary) print(dictionary.find_item(3)) print(dictionary.find_item(1)) print(dictionary.find_all_items(1)) dictionary.remove_item(2) print(dictionary) dictionary.remove_all_items(1) print(dictionary) def empty(self): return self.head == None def dictionary_size(self): count = 0 self.ptr = self.head while self.ptr != None: count = count + 1 self.ptr = self.ptr.next return count Sample Run { (1,2),(2,6),(3,9),(1,10) } 9 2 [2, 10] { (1,2),(3,9),(1,10)} { (3,9) }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY