Anonymous user
AVL tree: Difference between revisions
→{{header|Beed}}
Line 2,421:
else // item already exists
{
throw s;▼
}
}
Line 2,496 ⟶ 2,495:
operator>>(data)
{
if empty▼
{▼
throw "entry not found";▼
}▼
node = root;
repeat
{
throw "entry " + data.to_string() + " not found";
if data < node.data
{
Line 2,511 ⟶ 2,512:
else
{
if node.data < data
{
node = node.right;
}
else // item found
{
if !node.left.null() && !node.right.null()
{
replace = node.left;
while !replace.right.null()
{
replace = replace.right;
}
temp = node.data;
node.data = replace.data;
replace.data = temp;
node = replace;
}
from = direction.from_left;
if node != node.parent.left
{
from = direction.from_right;
}
if left == node
{
next = node;
next = next.next;
if header == next
{
left = header;
right = header;
}
else
{
left = next;
}
}
else
{
if header == node
{
previous = node;
previous = node.previous;
if header == previous
{
left = header;
right = header;
}
else
{
right = previous;
}
}
}
if node.left.null()
{
if node.parent == header
▲ {
root = node.right;▼
}▼
else▼
{▼
if node.parent.left == node▼
{
root
}
else
{
▲ {
▲ root.left = node.right;
}
else
{
}
}
▲ }
if !node.right.null()
{
node.right.parent = node.parent;
}
}▼
▲ else
▲ {
if node.parent == header▼
{▼
▲ root = node.left;
}
else
{
if node.parent
{
}
else
{
if node.parent.
}
else
▲ {
}
node.left.parent = node.parent;
▲ }
}
▲ node.left.parent = node.parent;
▲ }
}
return
operator[](data)
Line 2,696:
get(data)
{
▲ throw "entry not found";
node = root;
repeat
{
if node.is_null()
▲ throw "entry not found";
▲ }
if data < node.data
{
Line 2,736 ⟶ 2,735:
}
}
}
Line 2,788 ⟶ 2,786:
if s != l {out = out + ",";}
}
catch
}
out = out + "}";
|