-
-
Save metaxy/609510 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Baum | |
{ | |
public Baum() | |
{ | |
child0 = null; | |
child1 = null; | |
value = 0; | |
} | |
public Baum child0{set; get;} | |
public Baum child1{set; get;} | |
public int value { set; get; } | |
} | |
class Bla | |
{ | |
private int counterInnerNode = 0; | |
private int counterLeaf = 0; | |
private int counterLChild = 0; | |
private int counterRChild = 0; | |
private int counterOnly = 0; | |
private int counter2 = 0; | |
public Bla() | |
{ | |
} | |
public int countEmptyNodes(Baum b) | |
{ | |
if(b.child0 == null && b.child1 == null) | |
{ | |
return 2; | |
} | |
int ret = 0; | |
if (b.child0 != null) | |
ret += countEmptyNodes(b.child0); | |
else | |
ret += 1; | |
if (b.child1 != null) | |
ret += countEmptyNodes(b.child1); | |
else | |
ret += 1; | |
return ret; | |
} | |
public int countInnerNode(Baum b) | |
{ | |
if (b.child0 != null && b.child1 != null) | |
{ | |
counterInnerNode++; | |
} | |
if(b.child0 != null) | |
countInnerNode(b.child0); | |
if (b.child1 != null) | |
countInnerNode(b.child1); | |
return counterInnerNode; | |
} | |
public int countLeaf(Baum b) | |
{ | |
if (b.child0 == null && b.child1 == null) | |
{ | |
counterLeaf++; | |
} | |
if (b.child0 != null) | |
countLeaf(b.child0); | |
if (b.child1 != null) | |
countLeaf(b.child1); | |
return counterLeaf; | |
} | |
public int countLChild(Baum b) | |
{ | |
if (b.child1 != null) | |
{ | |
counterLChild++; | |
} | |
if (b.child0 != null) | |
countLChild(b.child0); | |
if (b.child1 != null) | |
countLChild(b.child1); | |
return counterLChild; | |
} | |
public int countRChild(Baum b) | |
{ | |
if (b.child0 != null) | |
{ | |
counterRChild++; | |
} | |
if (b.child1 != null) | |
countRChild(b.child1); | |
if (b.child0 != null) | |
countRChild(b.child0); | |
return counterRChild; | |
} | |
public int countOnly(Baum b) | |
{ | |
if ((b.child0 == null && b.child1 != null) || (b.child0 != null && b.child1 == null)) | |
{ | |
counterOnly++; | |
} | |
if (b.child1 != null) | |
countOnly(b.child1); | |
if (b.child0 != null) | |
countOnly(b.child0); | |
return counterOnly; | |
} | |
public int count2(Baum b) | |
{ | |
if (b.child0 != null && b.child1 != null) | |
{ | |
counter2++; | |
} | |
if (b.child1 != null) | |
count2(b.child1); | |
if (b.child0 != null) | |
count2(b.child0); | |
return counter2; | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Baum root = new Baum(); | |
Baum c1 = new Baum(); | |
Baum c2 = new Baum(); | |
Baum c3 = new Baum(); | |
c2.child0 = c3; | |
root.child0 = c1; | |
root.child1 = c2; | |
Bla b = new Bla(); | |
System.Console.WriteLine("EmptyNodes = "+b.countEmptyNodes(root)); | |
System.Console.WriteLine("InnerNodes = " + b.countInnerNode(root)); | |
System.Console.WriteLine("Leaf = " + b.countLeaf(root)); | |
System.Console.WriteLine("Count left = " + b.countLChild(root)); | |
System.Console.WriteLine("count r = " + b.countRChild(root)); | |
System.Console.WriteLine("only = " + b.countOnly(root)); | |
System.Console.WriteLine("2 = " + b.count2(root)); | |
System.Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment