Answered step by step
Verified Expert Solution
Question
1 Approved Answer
i have a data structures assignment in binary search trees please use my class methods and attributes and understand it then answer the questions kindly
i have a data structures assignment in binary search trees please use my class methods and attributes and understand it then answer the questions kindly write for each function a main program to test it after implementing each function my question is write a python function to non memeber function write it outside the class:
Sort DLL
Write the implementation of a nonmember function Sortdllthat returns the input dll after sorting it Hint: The idea here is that you need to create a BST from the elements in the given DLL
What is the complexity of your work?
use this class and watch out the private fields you ca not use them outside the class define setters and getters.
from DLList import DLL
from QueueSLL import QueueSLL
count
class BST:
class Node:
def initself data, leftNone, rightNone:
self.data data
self.left left
self.right right
self.depth
def strself:
return formatselfdata
def initself:
self.root None
def clearself:
self.root None
def isEmptyself:
return self.root is None
def rootValself:
if not self.isEmpty:
return self.root.data
else:
raise TypeErrorNone value"
def rootNodeself:
return self.root
def insertself val:
newNode self.Nodeval None, None
if self.isEmpty:
self.root newNode
return
p None
c self.root
while c is not None:
p c
if val cdata:
c cright
elif val cdata:
c cleft
else:
return
if val pdata:
pright newNode
else:
pleft newNode
def containsself val:
c self.root
while c is not None:
if val cdata:
return True
if val cdata:
c cleft
else:
c cright
return False
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started