Answered step by step
Verified Expert Solution
Link Copied!

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 Sort(dll)that 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 =0
class BST:
class _Node:
def __init__(self, data, left=None, right=None):
self._data = data
self._left = left
self._right = right
self._depth =0
def __str__(self):
return '({0})'.format(self._data)
def __init__(self):
self._root = None
def clear(self):
self._root = None
def isEmpty(self):
return self._root is None
def rootVal(self):
if not self.isEmpty():
return self._root._data
else:
raise TypeError("None value")
def rootNode(self):
return self._root
def insert(self, val):
newNode = self._Node(val, None, None)
if self.isEmpty():
self._root = newNode
return
p = None
c = self._root
while c is not None:
p = c
if val > c._data:
c = c._right
elif val < c._data:
c = c._left
else:
return
if val > p._data:
p._right = newNode
else:
p._left = newNode
def __contains__(self, val):
c = self._root
while c is not None:
if val == c._data:
return True
if val < c._data:
c = c._left
else:
c = c._right
return False

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

What is the maximum for ORIG_PRICE?

Answered: 1 week ago

Question

1 . Television News channels importantance of our Life pattern ?

Answered: 1 week ago

Question

1. How is the newspaper help to our daily life?

Answered: 1 week ago

Question

1. Prepare a short profile of Mikhail Zoshchenko ?

Answered: 1 week ago

Question

What is psychology disorder?

Answered: 1 week ago