-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AVL_Tree implement in python #177
base: master
Are you sure you want to change the base?
Conversation
self.root = None | ||
|
||
def insert(self, data): | ||
pNew = Node(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// set the Node(data) as a pNew
|
||
class AVL_Tree(object): | ||
def __init__(self): | ||
self.root = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// initialize the self.root
def insert(self, data): | ||
pNew = Node(data) | ||
|
||
if self.root == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if self.root == None, pNew becomes self.root
pCur = Cur; | ||
Cur = Cur.right | ||
|
||
if data < pCur.data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if data is smaller than pCur.data, pNew becomes pCur.left
|
||
if data < pCur.data: | ||
pCur.left = pNew | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if not, pNew becomes pCur.right
CCa.BF = 0 | ||
subroot = CCa | ||
|
||
if pa == None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if pa == None, subroot becomes self.root
|
||
if pa == None: | ||
self.root = subroot | ||
elif a == pa.left: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else if a == pa.left, subroot becomes pa.left
self.root = subroot | ||
elif a == pa.left: | ||
pa.left = subroot | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else, subroot becomes pa.right
Submission Checklist
master
branch of the repository.Type of Change
PR Description
AVL_Tree implement in python
Functions (insert, pre_order search, in_order search, post_order search)
Issue #173