Skip to content
Snippets Groups Projects
Commit c7c820b8 authored by s2-peng's avatar s2-peng
Browse files

Delete morse.py

parent d9574499
No related branches found
No related tags found
No related merge requests found
class MorseNode:
def __init__(self, c):
self.char = c
self.dot = None
self.dash = None
#←
def insertLeft(self,c):
self.dot = MorseNode(c)
return self.dot
#→
def insertRight(self,c):
self.dash = MorseNode(c)
return self.dash
root = MorseNode('*')
#1st
root.dash = MorseNode('T')
root.dot = MorseNode('E')
#2nd
root.dot.dot = MorseNode('I')
root.dot.dash = MorseNode('A')
root.dash.dot = MorseNode('N')
root.dash.dash = MorseNode('M')
#3rd
root.dot.dot.dot = MorseNode('S')
root.dot.dot.dash = MorseNode('U')
root.dot.dash.dot = MorseNode('R')
root.dot.dash.dash = MorseNode('W')
root.dash.dot.dot = MorseNode('D')
root.dash.dot.dash = MorseNode('K')
root.dash.dash.dot = MorseNode('G')
root.dash.dash.dash = MorseNode('O')
#4th
root.dot.dot.dot.dot = MorseNode('H')
root.dot.dot.dot.dash = MorseNode('V')
root.dot.dot.dash.dot = MorseNode('F')
root.dot.dot.dash.dash = MorseNode('')
root.dot.dash.dot.dot = MorseNode('L')
root.dot.dash.dot.dash = MorseNode('')
root.dot.dash.dash.dot = MorseNode('P')
root.dot.dash.dash.dash = MorseNode('J')
root.dash.dot.dot.dot = MorseNode("B")
root.dash.dot.dot.dash = MorseNode("X")
root.dash.dot.dash.dot = MorseNode("C")
root.dash.dot.dash.dash = MorseNode("Y")
root.dash.dash.dot.dot = MorseNode("Z")
root.dash.dash.dot.dash = MorseNode("Q")
root.dash.dash.dash.dot = MorseNode("")
root.dash.dash.dash.dash = MorseNode("")
#5
root.dot.dot.dot.dot.dot = MorseNode("5")
root.dot.dot.dot.dot.dash = MorseNode("4")
root.dot.dot.dot.dash.dot = MorseNode("")
root.dot.dot.dot.dash.dash = MorseNode("3")
root.dot.dot.dash.dot.dot = MorseNode("")
root.dot.dot.dash.dot.dash = MorseNode("¿")
root.dot.dot.dash.dash.dot = MorseNode("?")
root.dot.dot.dash.dash.dash = MorseNode("2")
root.dot.dash.dot.dot.dot = MorseNode("&")
root.dot.dash.dot.dot.dash = MorseNode("")
root.dot.dash.dot.dash.dot = MorseNode("+")
root.dot.dash.dot.dash.dash = MorseNode("")
root.dot.dash.dash.dot.dot = MorseNode("+")
root.dot.dash.dash.dot.dash = MorseNode("")
root.dot.dash.dash.dash.dot = MorseNode("")
root.dot.dash.dash.dash.dash = MorseNode("1")
root.dash.dot.dot.dot.dot = MorseNode("6")
root.dash.dot.dot.dot.dash = MorseNode("=")
root.dash.dot.dot.dash.dot = MorseNode("/")
root.dash.dot.dot.dash.dash = MorseNode("")
root.dash.dot.dash.dot.dot = MorseNode("")
root.dash.dot.dash.dot.dash = MorseNode("")
root.dash.dot.dash.dash.dot = MorseNode("(")
root.dash.dot.dash.dash.dash= MorseNode("")
root.dash.dash.dot.dot.dot = MorseNode("7")
root.dash.dash.dot.dot.dash = MorseNode("")
root.dash.dash.dot.dash.dot = MorseNode("")
root.dash.dash.dot.dash.dash = MorseNode("")
root.dash.dash.dash.dot.dot = MorseNode("8")
root.dash.dash.dash.dot.dash = MorseNode("")
root.dash.dash.dash.dash.dot = MorseNode("9")
root.dash.dash.dash.dash.dash = MorseNode("0")
root.dot.dash.dot.dash.dot.dash = MorseNode(".")
root.dash.dash.dot.dot.dash.dash = MorseNode(",")
root.dash.dot.dash.dash.dot.dash = MorseNode(")")
root.dash.dot.dot.dot.dot.dash = MorseNode("-")
root.dash.dash.dot.dot.dot.dash = MorseNode("i")
root.dot.dot.dash.dash.dot.dash = MorseNode("_")
root.dot.dash.dash.dash.dash.dot = MorseNode("'")
root.dash.dash.dash.dot.dot.dot = MorseNode(":")
root.dot.dash.dot.dot.dash.dot = MorseNode("")
root.dash.dot.dash.dot.dash.dash = MorseNode("!")
root.dash.dot.dash.dot.dash.dot = MorseNode(";")
root.dot.dot.dot.dash.dot.dot.dash = MorseNode("$")
def encode(tree, morse):
current_node = tree
for morse_symbol in morse:
print(morse_symbol)
if (morse_symbol == '.'):
current_node = current_node.dot
elif (morse_symbol == '-'):
current_node = current_node.dash
return current_node.char
class BinaryTree:
def __init__(self):
self.root = root
def encode(self,letter):
node = self.findMorseCode(self.root,'',letter)
def findMorseCode(self,node,letter):
if node==None:
return None
if node ==root:
node.morseCode=''
if node.char==letter:
return node.char
next = self.findMorseCode(node.dot,'.',letter)
if next!=None:
return next
else:
return self.findMorseCode(node.dash,'-',letter)
def decode(self,moreCode):
letter = self.root
for c in morseCode:
if c == '':
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment