Parametric polymorphism: Difference between revisions
Content added Content deleted
m (Fixed lang tags.) |
No edit summary |
||
Line 54: | Line 54: | ||
left->replace_all (new_value); |
left->replace_all (new_value); |
||
right->replace_all (new_value); |
right->replace_all (new_value); |
||
}</lang> |
|||
=={{header|C sharp|C#}}== |
|||
<lang csharp>namespace RosettaCode { |
|||
class BinaryTree<T> { |
|||
T value; |
|||
BinaryTree<T> left; |
|||
BinaryTree<T> right; |
|||
public void ReplaceAll(T value) { |
|||
this.value = value; |
|||
if (left != null) { |
|||
left.ReplaceAll(value); |
|||
} |
|||
if (right != null) { |
|||
right.ReplaceAll(value); |
|||
} |
|||
} |
|||
} |
|||
}</lang> |
|||
Sample that creates a tree to hold int values: |
|||
<lang csharp>namespace RosettaCode { |
|||
class Program { |
|||
static void Main(string[] args) { |
|||
BinaryTree<int> tree = new BinaryTree<int>(); |
|||
tree.ReplaceAll(5); |
|||
} |
|||
} |
|||
}</lang> |
}</lang> |
||