Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Chianc-Leocadio-EDB2-PROVA2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chianc Leocádio de Lima
Chianc-Leocadio-EDB2-PROVA2
Commits
66b020fe
Commit
66b020fe
authored
6 years ago
by
Chianc Leocádio de Lima
Browse files
Options
Downloads
Patches
Plain Diff
arvore binaria com nós
parent
87f3c070
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
binaryTree.py
+100
-0
100 additions, 0 deletions
binaryTree.py
with
100 additions
and
0 deletions
binaryTree.py
0 → 100644
+
100
−
0
View file @
66b020fe
class
Node
:
def
__init__
(
self
,
data
=
None
,
father
=
None
,
left
=
None
,
right
=
None
):
self
.
data
=
data
self
.
father
=
father
self
.
left
=
left
self
.
right
=
right
#____________________________________________________________________________#
def
insert
(
data
,
father
):
filho
=
Node
(
data
,
father
)
if
father
.
left
==
None
:
father
.
left
=
filho
return
True
elif
father
.
left
!=
None
and
father
.
right
==
None
:
father
.
right
=
filho
return
True
else
:
return
False
#____________________________________________________________________________#
def
searchPre
(
data
,
root
):
if
root
==
None
:
return
None
if
root
.
data
==
data
:
return
root
else
:
return
searchPre
(
data
,
root
.
left
)
or
searchPre
(
data
,
root
.
right
)
#____________________________________________________________________________#
def
remove
(
root
):
aRemover
=
root
if
aRemover
.
left
==
None
and
aRemover
.
right
==
None
:
if
aRemover
.
father
.
left
==
aRemover
:
aRemover
.
father
.
left
=
None
aRemover
=
None
return
True
else
:
aRemover
.
father
.
right
=
None
aRemover
=
None
return
True
elif
aRemover
.
left
==
None
or
aRemover
.
right
==
None
:
if
aRemover
.
left
==
None
:
aRemover
.
right
.
father
=
aRemover
.
father
aRemover
=
aRemover
.
right
aRemover
.
right
=
None
return
True
else
:
aRemover
.
left
.
father
=
aRemover
.
father
aRemover
=
aRemover
.
left
aRemover
.
left
=
None
return
True
else
:
substituto
=
aRemover
while
substituto
.
left
!=
None
and
substituto
.
right
!=
None
:
substituto
=
substituto
.
left
substituto
.
father
.
left
=
None
substituto
=
aRemover
return
True
#__________________________________________________________________________________#
def
showTree
(
root
):
if
root
:
print
(
root
.
data
)
showTree
(
root
.
left
)
showTree
(
root
.
right
)
#____________________________________________________________________________________#
a
=
Node
(
0
)
#formas de inserir os nós
insert
(
2
,
a
)
insert
(
5
,
a
)
a
.
left
.
left
=
Node
(
6
,
a
.
left
)
a
.
right
.
right
=
Node
(
7
,
a
.
right
)
insert
(
4
,
a
.
left
)
insert
(
3
,
a
.
right
)
#mostrar os nós da árvore
showTree
(
a
)
print
(
searchPre
(
4
,
a
))
#retorna o objeto
print
(
remove
(
searchPre
(
4
,
a
)))
#remove o objeto encontrado na busca (print "True" qdo remove)
print
(
searchPre
(
4
,
a
))
#retorna None
#mostrar os nós da árvore, agora sem o nó removido
showTree
(
a
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment