-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3fix.py
More file actions
121 lines (106 loc) · 3.24 KB
/
lab3fix.py
File metadata and controls
121 lines (106 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 4 19:38:45 2018
@author: JesusMHernandez
"""
from AVLNode import AVLNode
from AVLTree import AVLTree
from RBTree import RBTree
from RBTNode import RBTNode
engish_words = None
fileName = "testW.txt"
def main():
global engish_words
valid = False
# print(count_anagrams("max"))
# print(print_anagrams("max"))
while(valid == False):
print("What type of Binary Tree? ")
answer = input("Enter 'A' for AVL Tree or 'B' for Red-Black Tree: ")
answer = answer.lower()
if (answer != 'a' and answer != 'b'):
valid = False
print("Error")
else:
valid = True
if(answer == 'a'):
print("you have selected AVL Tree")
engish_words = AVL()
else:
print("You have selected Red-Black Tree")
engish_words = RBT()
# tree = AVL()
# engish_word(tree)
def engish_word(word):
avlTree = AVLTree()
#opens file and puts into tree
with open(fileName) as f:
for line in f:
node = (line.lower()) #this line makes every word a lower case
node = AVLNode(lowerCase)
avlTree.insert(node)
avlTree.search("Max")
def find_largest(file):
count = 0
with open(fileName) as f:
for line in f:
temp = count_anagrams(line)
if temp > count:
count = temp
largest = line
return largest
def count_anagrams(word, prefix=""):
if len(word) <= 1:
str = prefix + word
if engish_words(str):
return 1
return 0
print(prefix + word)
else:
count = 0
for i in range(len(word)):
cur = word[i: i + 1]
before = word[0: i] # letters before cur
after = word[i + 1:] # letters after cur
if cur not in before: # Check if permutations of cur have not been generated.
count += count_anagrams(before + after, prefix + cur)
return count
#function to print anagrams of a word
def print_anagrams(word, prefix=""):
if len(word) <= 1:
str = prefix + word
if engish_words("Max"):
print(prefix + word)
else:
for i in range(len(word)):
cur = word[i: i + 1]
before = word[0: i] # letters before cur
after = word[i + 1:] # letters after cur
if cur not in before: # Check if permutations of cur have not been generated.
print_anagrams(before + after, prefix + cur)
def AVL():
avlTree = AVLTree()
#opens file and puts into tree
with open(fileName) as f:
for line in f:
node = (line.lower()) #this line makes every word a lower case
node = AVLNode(lowerCase)
avlTree.insert(node)
return avlTree
def RBT():
rbtTree = RBTree()
with open(fileName) as f:
for line in f:
node = (line.lower()) #this line makes every word a lower case
rbtTree.insert(node)
return rbtTree
'''
class Node():
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
self.count = 0
'''
main()