Skip to content
Snippets Groups Projects
Commit b683b7af authored by Mamadu-lamarana Bah's avatar Mamadu-lamarana Bah :speech_balloon:
Browse files

suppression cas simple fonctionne

parent dc8fb3a5
No related branches found
No related tags found
No related merge requests found
......@@ -68,4 +68,4 @@ Suite suppression, fonctionne pour le cas d'une feuille.
### emaine 12
Création du Readme, suite suppression.
\ No newline at end of file
Suite suppression.
\ No newline at end of file
graph {
"[12, 42]"
"[2, 3]"
"[12, 42]" -- "[2, 3]"
"[2, 3]"
"[25]"
"[12, 42]" -- "[25]"
"[25]"
"[50]"
"[12, 42]" -- "[50]"
"[50]"
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.43.0 (0)
-->
<!-- Title: %3 Pages: 1 -->
<svg width="230pt" height="116pt"
viewBox="0.00 0.00 230.34 116.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 112)">
<title>%3</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-112 226.34,-112 226.34,4 -4,4"/>
<!-- [12, 42] -->
<g id="node1" class="node">
<title>[12, 42]</title>
<ellipse fill="none" stroke="black" cx="117.1" cy="-90" rx="46.59" ry="18"/>
<text text-anchor="middle" x="117.1" y="-86.3" font-family="Times,serif" font-size="14.00">[12, 42]</text>
</g>
<!-- [2, 3] -->
<g id="node2" class="node">
<title>[2, 3]</title>
<ellipse fill="none" stroke="black" cx="35.1" cy="-18" rx="35.19" ry="18"/>
<text text-anchor="middle" x="35.1" y="-14.3" font-family="Times,serif" font-size="14.00">[2, 3]</text>
</g>
<!-- [12, 42]&#45;&#45;[2, 3] -->
<g id="edge1" class="edge">
<title>[12, 42]&#45;&#45;[2, 3]</title>
<path fill="none" stroke="black" d="M98.49,-73.12C84.69,-61.34 66.01,-45.39 52.51,-33.86"/>
</g>
<!-- [25] -->
<g id="node3" class="node">
<title>[25]</title>
<ellipse fill="none" stroke="black" cx="117.1" cy="-18" rx="29.5" ry="18"/>
<text text-anchor="middle" x="117.1" y="-14.3" font-family="Times,serif" font-size="14.00">[25]</text>
</g>
<!-- [12, 42]&#45;&#45;[25] -->
<g id="edge2" class="edge">
<title>[12, 42]&#45;&#45;[25]</title>
<path fill="none" stroke="black" d="M117.1,-71.7C117.1,-60.85 117.1,-46.92 117.1,-36.1"/>
</g>
<!-- [50] -->
<g id="node4" class="node">
<title>[50]</title>
<ellipse fill="none" stroke="black" cx="193.1" cy="-18" rx="29.5" ry="18"/>
<text text-anchor="middle" x="193.1" y="-14.3" font-family="Times,serif" font-size="14.00">[50]</text>
</g>
<!-- [12, 42]&#45;&#45;[50] -->
<g id="edge3" class="edge">
<title>[12, 42]&#45;&#45;[50]</title>
<path fill="none" stroke="black" d="M134.34,-73.12C147.31,-61.18 164.92,-44.95 177.47,-33.39"/>
</g>
</g>
</svg>
......@@ -96,12 +96,12 @@ class Node() :
(Node([50, 52]), 1)
>>> node = Node([12, 42], [Node([2, 3]), Node([25]), Node([50])])
>>> node.insert(1, 2)
(False, 12, Node([2]), Node([42]))
(False, 12, Node([2], [Node([1]), Node([3])]), Node([42], [Node([25]), Node([50])]))
>>> node.search(1)
(Node([1]), 0)
>>> node = Node([12, 42], [Node([2, 4], [Node([0, 1]), Node([3]), Node([7, 8])]), Node([25]), Node([50])])
>>> node.insert(6, 2)
(False, 12, Node([4]), Node([42]))
(False, 12, Node([4], [Node([2], [Node([0, 1]), Node([3])]), Node([7], [Node([6]), Node([8])])]), Node([42], [Node([25]), Node([50])]))
>>> node = Node([12, 42], [Node([2, 3, 4]), Node([25]), Node([50])])
>>> node.insert(1, 3)
......@@ -137,8 +137,20 @@ class Node() :
Exemple(s):
>>> node = Node([12, 42], [Node([3, 4]), Node([25, 26]), Node([50, 58])])
>>> node.suppression(50, 2)
True
>>> node.search(50)
>>> node.suppression(26, 2)
True
>>> node.search(26)
>>> node.suppression(25, 2)
True
>>> node.search(25)
>>> node.suppression(12, 2)
True
>>> node
>>> node.suppression(3, 2)
True
>>> node
"""
(found, index) = recherche_dichotomique(value, self.keys)
if (self.isLeaf()) :
......@@ -147,33 +159,32 @@ class Node() :
else:
(ok) = self.childs[index].suppression(value, k, False)
if (not ok):
if(index - 1 >= 0 and (len(self.childs[index-1].keys) >= k//2)):
if(index - 1 >= 0 and (len(self.childs[index-1].keys) - 1 >= k//2)):
borrowed = self.childs[index-1].keys.pop()
replaced = self.keys.pop(0)
self.keys.insert(0, borrowed)
self.childs[index].keys.insert(0, replaced)
elif(index + 1 < len(self.childs) and (len(self.childs[index+1].keys) >= k//2)):
borrowed = self.childs[index+1].keys.pop(0)
elif(index + 1 < len(self.childs) and (len(self.childs[index+1].keys) - 1 >= k//2)):
borrowed = self.childs[index+1].keys.pop()
replaced = self.keys.pop()
self.keys.insert(len(self.keys), borrowed)
self.childs[index].keys.insert(len(self.childs), replaced)
return ok
# def suppr(self, value, k) :
# """
# >>> a = Node([12, 42], [Node([3]), Node([25]), Node([50])])
# >>> a.suppr(11)
# False
# """
# found = self.search(value)
# if (found) :
# return None
# else :
# return False
self.childs[index].keys.insert(len(self.keys), borrowed)
self.childs[index].keys.insert(len(self.childs[index].keys), replaced) # len(self.childs)
else:
if(index-1 >= 0):
replaced = self.keys.pop(index-1)
borrowed = self.childs[index-1].keys.pop()
self.childs[index].keys.insert(len(self.childs[index].keys), replaced)
self.childs[index].keys.insert(0, borrowed)
del self.childs[index-1]
elif(index + 1 < len(self.childs)):
replaced = self.keys.pop(index)
borrowed = self.childs[index+1].keys.pop()
self.childs[index].keys.insert(0, borrowed)
self.childs[index].keys.insert(len(self.childs[index].keys), replaced)
del self.childs[index+1]
ok = not ok
return ok
def splitNode(self) :
"""
......@@ -208,8 +219,7 @@ class Node() :
res.extend(self.childs[len(self.childs)-1].linearisation())
return res
def __repr__(self) :
return (f"Node({self.keys}"
+ (f", {self.childs})" if len(self.childs) > 0 else ")"))
......
......@@ -20,6 +20,6 @@ class Visualization() :
self.add_node_to_graph(childKeys)
def render(self):
self.g.format = 'svg'
self.g.format = 'jpg'
self.g.render(directory='ArbreB', view=True)
\ 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