Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

highgarden7
Copy link

@highgarden7 highgarden7 commented Jun 6, 2018

Submission Checklist

  • Your pull request targets the master branch of the repository.
  • You have only one commit (if not, squash them into one commit).
  • You have read the Contributing guidelines and your changes follow them.

Type of Change

  • Bug fix
  • New implementation

PR Description

AVL_Tree implement in python
Functions (insert, pre_order search, in_order search, post_order search)

Issue #173

self.root = None

def insert(self, data):
pNew = Node(data)

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

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:
Copy link

@kwanukwanu kwanukwanu Jun 7, 2018

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:

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:

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:

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:

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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants