Question: TRANSLATE THIS PSEUDO CODE INTO JAVA. A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open

TRANSLATE THIS PSEUDO CODE INTO JAVA.

A high-level algorithm for the traceFile method is given below: Initialize stack

A high-level algorithm for the traceFile method is given below: Initialize stack to an empty stack of CodeBlocks. Open file using filename. while file has lines line = next line in file. if line is not empty and line does not start with '#' indents = number of spaces in line / SPACES_COUNT. while indents is less than size of stack if indents is 0 Close file and return the total complexity of stack.top. else old Top stack.pop() old TopComplexity = total complexity of old Top if oldTopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = old TopComplexity if line contains a keyword keyword=keyword in line. if keyword is "for" Determine the complexity at end of line ("N:" or "log_N: ") Create new 0(n) or 0(log(n)) CodeBlock and push onto stack. else if keyword is "while" else loopVariable = variable being updated (first token after "while"). Create new 0(1) CodeBlock with loopVariable and push onto stack. else Create new 0(1) CodeBlock and push onto the stack. else if stack.top is a "while" block and line updates stack.top's loopVariable Update the blockComplexity of stack.top. Ignore line. while size of stack > 1 oldTop stack.pop() oldTopComplexity = total complexity of oldTop if old TopComplexity is higher order than stack.top's highest sub-complexity stack.top's highest sub-complexity = oldTopComplexity Return stack.pop().

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the Java code translation of the provided pseudocode l... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!