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

search et debut insertion

parent 141276f7
Branches
No related tags found
No related merge requests found
......@@ -7,15 +7,10 @@ class Btree() :
self.root = root
self.k = k
def search(self, value, node=self.root):
(found, index) = node.search(value)
if (found):
return (node, index)
elif ( node.isLeaf() ):
return None
else :
self.search(value, node.childs[index])
def search(self, value):
return self.root.search(value)
# incomplet
def insertion(self, value):
if (self.root == None):
self.root = Bnode.Node(self.k)
......@@ -24,6 +19,10 @@ class Btree() :
if ( len(self.root) == self.k):
new_root = Bnode.Node(self.k)
new_root.childs[0] = self.root
if (self)
else:
self.root.insert_not_full(value)
......
......@@ -2,9 +2,11 @@ from util import recherche_dichotomique
class Node() :
def __init__(self, nbKey) :
def __init__(self, k) :
self.parent =
self.keys = []
self.childs = []
self.k = k
def isLeaf():
return (len(self.childs) == 0)
......@@ -12,8 +14,35 @@ class Node() :
def getSize(self) :
return len(Keys)
def serach(self, k):
return recherche_dichotomique(k, self.keys)
def serach(self, value):
(found, index) = recherche_dichotomique(value, self.keys)
if (found):
return (node, index)
elif ( node.isLeaf() ):
return None
else :
self.childs[index].search(value)
def insert_not_full(self, value):
(found, index) = self.search(value)
if (self.isLeaf()) :
if (not found):
self.keys.insert() = value
else :
if (len(self.childs[index]) == self.k) :
self.childs[index].splitNode(index)
if (value > self.keys[index]) :
index += 1
self.childs[index].insert_not_full(value)
# j'ai pas encore bien compris comment m'y prendre
def splitNode(self) :
parent = Node(self.k)
m = self.keys[(len(self.node.keys))//2]
#def getSizeNode() :
#def getPos() :
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment