| <<O>> Difference Topic BinarySearchTreeExample (r1.2 - 11 Apr 2005 - TWikiGuest) |
| Added: | |
| > > |
public |
| Changed: | |
| < < |
?IntTreeNode |
| > > | let theleft = left; |
| Changed: | |
| < < | theleft = new IntTreeNode? (m_key: key, m_value: value); |
| > > | left = new IntTreeNode? (m_key: key, m_value: value); |
| Added: | |
| > > | left = theleft; |
| Changed: | |
| < < |
?IntTreeNode |
| > > | let theright = right; |
| Changed: | |
| < < | theright = new IntTreeNode? (m_key: key, m_value: value); |
| > > | right = new IntTreeNode? (m_key: key, m_value: value); |
| Added: | |
| > > | right = theright; |
| Changed: | |
| < < | public ?U getValue(T key) { |
| > > | override ?U getValue(T key) { |
| Changed: | |
| < < |
?IntTreeNode |
| > > | return left.getValue(key); |
| Changed: | |
| < < |
?IntTreeNode |
| > > | return right.getValue(key); |
| Changed: | |
| < < |
?IntTreeNode |
| > > | let mycontent = content; |
| Changed: | |
| < < | mycontent = new IntTreeNode? (m_key: key, m_value: value); |
| > > | content = new IntTreeNode? (m_key: key, m_value: value); |
| Added: | |
| > > | content = mycontent; |
| Changed: | |
| < < |
?IntTreeNode |
| > > | return content.getValue(key); |
| <<O>> Difference Topic BinarySearchTreeExample (r1.1 - 11 Apr 2005 - TWikiGuest) |
| Added: | |
| > > |
%META:TOPICINFO{author="TWikiGuest" date="1113237420" format="1.0" version="1.1"}%
%META:TOPICPARENT{name="CodeExamples"}%
<Comparable T,U>
class IntTreeNode <T,U> {
private !T m_key;
private U m_value;
private ?IntTreeNode<T,U> left = null;
private ?IntTreeNode<T,U> right = null;
public void add (!T key, U value) {
if (key == m_key)
{
m_value = value;
}
else if (key < m_key)
{
?IntTreeNode<T,U> theleft = left;
if (theleft == null) {
theleft = new IntTreeNode (m_key: key, m_value: value);
} else {
theleft.add (key, value);
}
}
else
{
?IntTreeNode<T,U> theright = right;
if (theright == null) {
theright = new IntTreeNode (m_key: key, m_value: value);
} else {
theright.add (key, value);
}
}
}
public ?U getValue(T key) {
if (key == m_key) {
return m_value;
} else if (key < m_key) {
?IntTreeNode<T,U> myleft = left;
return myleft != null ? myleft.getValue(key) : null;
} else {
?IntTreeNode<T,U> myright = right;
return myright != null ? myright.getValue(key) : null;
}
}
}
<Comparable T,U>
class IntTree <T,U> {
?IntTreeNode<T,U> content = null;
public void add (!T key, !U value) {
?IntTreeNode<T,U> mycontent = content;
if (mycontent == null) {
mycontent = new IntTreeNode (m_key: key, m_value: value);
} else {
mycontent.add (key, value);
}
}
public ?U getValue(!T key)
{
?IntTreeNode<T,U> mycontent = content;
return mycontent != null ? mycontent.getValue(key) : null;
}
}
-- Raboof - 11 Apr 2005 |
| Topic BinarySearchTreeExample . { View | Diffs | r1.2 | > | r1.1 | More } |
|
Revision r1.1 - 11 Apr 2005 - 16:37 GMT - TWikiGuest Revision r1.2 - 11 Apr 2005 - 18:04 GMT - TWikiGuest |
Copyright © 1999-2003 by the contributing authors.
All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems regarding TWiki? Send feedback. |