Hausuebung_12_BinaerBaeume

Hausuebung_12_BinaerBaeume - int = 0 int countSonsNextLevel...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
05 Altinger Harald 0630936
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Altinger Harald 0630936
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
//------------------------------------ //funktion searches for the min branch within a binary tree //the idea is to seek per node; first all left elements, afterwards all left int seekRecursive(int currentDepth, int minLength, currentNode) { //termination; if node has no sons it's the end of a branch return currentDepth; //if another branch is already shorter if(tiefe > currentDepth) return currentDepth; currentDepth = seekRecursive(currentDepth+1,minLength,left(currentNode)); currentDepth = seekRecursive(currentDepth+1,minLength,right(currentNode)); return currentDepth;
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
//------------------------------------ //funktion searches for the min branch within a binary tree //needs the root of the tree as calling parameter //the idea is to seek per level int seekLoop(root) { int currentDepth;
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int countSonsCurrentLevel = 0; int countSonsNextLevel = 0; int countElementsCurrentLevel; int countCurrentElement; //initial; pushToFifo(root); countElementsCurrentLevel = 1; // root is the only element at level one currentDepth = 0; //define root level as level 0 while(1) { for(countCurrentElement = 0; countCurrentElement < countElementsCurrentLevel; countCurrentElement++) { //get next element from fifo k=getNextFifoElement(); //stop condition; first node with no sons represent the shortes branch if(left(k) == null) && (right(k) == null) return currentDepth; else { //add son to fifo if(right(k) != null) { pushToFifo(right(k)); countSonsNextLevel++; } if(left(k) != null) { pushToFifo(left(k)); countSonsNextLevel++; } } } //reset for next level countElementsCurrentLevel = countSonsNextLevel; countSonsNextLevel = 0; //increase leve currentDepth++; }...
View Full Document

{[ snackBarMessage ]}

Page1 / 6

Hausuebung_12_BinaerBaeume - int = 0 int countSonsNextLevel...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online