Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Just names (format: fname lname) and birthdays (format: yyyy-mm-dd) as data attr

ID: 3729257 • Letter: J

Question

Just names (format: fname lname) and birthdays (format: yyyy-mm-dd) as data attributes are sufficient.

Implement your BST as a link-based ADT - use Node

For the data, create a text file of data in a random fashion - name or birthday entry per line.

Read the data to create your BST for the database by name or birthday as needed - remember two different trees will be needed and the node insertions will be different depending on which data tree it is.

Write out the listing of everyone by name to a file (separate from your input) using a post-order traversal mechanism.

Write out the listing of everyone by birthday to a different file using a breadth-first traversal mechanism.

Write a program that maintains a database containing data, such as name and birthday, about your friends and relatives. You should be able to enter, remove, modify, or search this data. Initially, you can assume that the names are unique. The program should be able to save the data in a file for use later. 5. Design a class to represent the database and another class to represent the people. Use a binary search tree of people as a data member of the database class. You can enhance this problem by adding an operation that lists everyone who satisfies a given criterion. For example, you could list people born in a given month. You should also be able to list everyone in the database

Explanation / Answer

class node:
def __init__(self,right,left,name):
self.right=right
self.left=left
self.name=name
self.visited=False

class io:
file = open("name.txt","r")
file1 = open("post.txt","w")
file2 = open("bfs.txt","w")

def read(self):
#print "enter"
i = 0
for line in self.file:
#print line
if i==0:
root=node(None,None,line.strip())
else:
insert(root,line.strip())
i+=1
#print root
return root

def writepost(self,name):
self.file1.write(name+" ")

def writebfs(self,name):
self.file2.write(name+" ")


# insert name or birthday
def insert(root,name):
if root==None:
root=node(None,None,name)

elif name>root.name:
a=insert(root.right,name)
root.right=a
else:
a=insert(root.left,name)
root.left=a
return root


def post_order_print(root):
if not root:
return   
post_order_print(root.left)
post_order_print(root.right)
io().writepost(root.name)


def bfs(root):
if not root:
return
else:
l=[root]
while len(l)!=0:
t = l.pop(0)
io().writebfs(t.name)
if t.left!=None:
l.append(t.left)
if t.right!=None:
l.append(t.right)
  
  
a=io()
r=a.read()
#print r
post_order_print(r)
bfs(r)

Ex of name.txt

8
1
2
3
0

Note: To insert name or birthday make changes in name,txt