using System.Collections;
using System.Collections.Generic;
public static void Main()
var node1 = new Node<int>(null,null,0);
var node2 = new Node<int>(null,null,1);
var node3 = new Node<int>(node1,node2,3);
var node4 = new Node<int>(node3,null,4);
foreach(var value in node4){
public class Node<T> : IEnumerable<T>{
private Node<T> leftNode;
private Node<T> rightNode;
public Node(Node<T> leftNode,Node<T> rightNode,T value){
this.leftNode = leftNode;
this.rightNode = rightNode;
public IEnumerator<T> GetEnumerator()
foreach(var value in this.leftNode){
if(this.rightNode!=null){
foreach(var value in this.rightNode){
IEnumerator IEnumerable.GetEnumerator(){
return this.GetEnumerator();