Skip to content

Commit

Permalink
Still not working
Browse files Browse the repository at this point in the history
  • Loading branch information
deniscostadsc committed Jul 11, 2024
1 parent fcba11b commit 5fd33fd
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 48 deletions.
36 changes: 26 additions & 10 deletions solutions/beecrowd/1201/1201.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,33 @@ def postfix_print(self):
self.__traverse_print(traverse_type='POSTFIX')
print()

def remove(self, number):
_remove(self, number)

def remove(tree, number):
if tree.number == None:
return tree

if number > tree.number and tree.right:
tree.right = tree.right.remove(number)
return tree
if number < tree.number and tree.left:
tree.left = tree.left.remove(number)
def _remove(tree, number):
if not tree:
return tree
if number < tree.number:
tree.left = _remove(tree.left, number)
elif number > tree.number:
tree.right = _remove(tree.right, number)
else:
if not tree.left:
return tree.right
elif not tree.right:
return tree.left
else:
successor_parent = tree
successor = tree.right
while successor.left:
successor_parent = successor
successor = successor.left
tree.number = successor.number
if successor_parent.left is successor:
successor_parent.left = successor.right
else:
successor_parent.right = successor.right
return tree


def main():
Expand All @@ -103,7 +119,7 @@ def main():
else:
print(f'{number} nao existe')
case ['R', number]:
remove(tree, number)
tree.remove(number)
case ['PREFIXA']:
tree.prefix_print()
case ['INFIXA']:
Expand Down
54 changes: 38 additions & 16 deletions solutions/beecrowd/1201/in.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,63 @@
I 8
INFIXA
P 10
I 10
INFIXA
P 10
P 4
I 4
P 4
INFIXA
P 1
P 7
I 7
INFIXA
P 7
P 8
INFIXA
R 8
INFIXA
P 8
PREFIXA
INFIXA
POSFIXA
P 3
I 3
P 3
P 2
I 2
p 2
P 30
P 1
I 1
P 1
PREFIXA
INFIXA
POSFIXA
R 7
PREFIXA
INFIXA
POSFIXA
P 2
R 2
P 2
PREFIXA
INFIXA
POSFIXA
I 12
R 12
P 2
P 32
PREFIXA
INFIXA
POSFIXA
I 12
I 11
P 87
P 1
R 12
PREFIXA
INFIXA
POSFIXA
I 8
I 15
R 11
PREFIXA
Expand Down Expand Up @@ -60,30 +85,31 @@ INFIXA
POSFIXA
R 15
R 11
P 5
I 20
P 4
R 15
PREFIXA
INFIXA
POSFIXA
P 20
I 20
I 10
P 20
I 15
I 16
P 17
I 17
P 17
I 5
I 7
I 6
I 8
I 3
I 4
I 2
I 1
P 30
I 30
I 25
P 30
I 35
I 40
P 41
I 41
P 41
I 39
I 38
I 37
Expand All @@ -96,19 +122,15 @@ R 30
INFIXA
R 20
PREFIXA
I 20
R 40
POSFIXA
I 11
I 5
I 7
I 4
I 32
I 17
P 40
I 40
P 40
I 15
I 28
I 35
I 42
I 25
I 24
Expand Down
82 changes: 60 additions & 22 deletions solutions/beecrowd/1201/out.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,86 @@
8
10 nao existe
8 10
10 existe
4 nao existe
4 existe
4 8 10
1 nao existe
7 nao existe
4 7 8 10
7 existe
8 existe
4 7 8 10
4 7 10
8 nao existe
7 4 10
4 7 10
4 10 7
3 nao existe
3 existe
2 nao existe
2 existe
30 nao existe
1 nao existe
1 existe
7 4 3 2 1 10
1 2 3 4 7 10
1 2 3 4 10 7
4 3 2 1 10
1 2 3 4 10
1 2 3 10 4
2 existe
2 nao existe
4 3 1 10
1 3 4 10
1 3 10 4
2 nao existe
32 nao existe
4 3 1 10
1 3 4 10
1 3 10 4
87 nao existe
1 existe
4 3 1 10 11
1 3 4 10 11
1 3 11 10 4
4 3 1 10 8 15
1 3 4 8 10 15
1 3 8 15 10 4
3 1 10 8 15
1 3 8 10 15
1 8 15 10 3
3 1 8 15
1 3 8 15
1 15 8 3
1 8 15
1 8 15
15 8 1
8 15
8 15
15 8
4 3 1 10 15
1 3 4 10 15
1 3 15 10 4
3 1 10 15
1 3 10 15
1 15 10 3
3 1 15
1 3 15
1 15 3
1 15
1 15
15 1
15
15
15
15
15
15
5 nao existe
4 nao existe
20
20
20
20 existe
1 2 3 4 5 6 7 8 10 15 16 17 20 20 25 30 35 37 38 39 40 41
20 20 8 5 3 2 1 4 7 6 15 16 17 30 25 35 40 39 38 37 41
1 2 4 3 6 5 17 16 15 7 20 25 37 38 39 41 40 35 30 20
1 2 3 4 5 6 7 15 16 17 20 20 25 35 37 38 39 40 41
20 7 5 3 2 1 4 6 15 16 17 25 35 40 39 38 37 41
1 2 4 3 6 5 20 17 16 15 7 37 38 41 39 35 25 20
1 2 3 4 4 5 5 6 7 7 11 15 15 16 17 17 20 20 23 24 25 25 28 35 35 37 38 39 40 41 42
20 existe
17 nao existe
17 existe
30 nao existe
30 existe
41 nao existe
41 existe
2 3 4 5 6 7 15 16 17 20 20 25 30 35 37 38 39 40 41
20 20 15 5 3 2 4 7 6 16 17 30 25 35 40 39 38 37 41
2 4 3 6 7 5 17 16 15 20 25 37 38 39 41 40 35 30 20
2 3 4 5 6 7 15 16 17 20 20 25 35 37 38 39 40 41
20 15 5 3 2 4 7 6 16 17 25 35 40 39 38 37 41
2 4 3 6 7 5 20 17 16 15 37 38 41 39 35 25 20
40 nao existe
40 existe
2 3 4 4 5 5 6 7 7 11 15 15 16 17 20 20 23 24 25 25 28 35 35 37 38 39 40 41 42

0 comments on commit 5fd33fd

Please sign in to comment.