dotNetChris @ Marisic.Net

July 30, 2008

A Programming Job Interview Challenge #13

Basically the question this is looking to solve is handling proper expression syntax/precedence similar to the standard calculator problem of solving 5+5/5=6 as opposed to solving it as 2.

Example of a legal expression: “([](<{}>))”.

Example of an illegal expression: “({<)>}”.

Which involes a much simpler version of Prefix or PostFix/Reverse Polish Notation ( )  than the math expression since there are only pairs of operations. A rather basic psuedo code implementation of this could be done as follows

HashTable Close [ ")" -> "(", "}" -> "{", ">" -> "<", "]” -> “[" ]; Stack holder;

Read expression

do while not end of expression {

if(close.ContainsKey(expression[i])) –Check to see if letter is a closing operand

{ –Reached closing operand, top of stack should be matching opening operand

if(close[expression[i] != stack.PopTop()) throw InvalidExpressionException


Push (expr[i])

} –Do looping to end of expression


The Shocking Blue Green Theme Blog at


Get every new post delivered to your Inbox.

Join 242 other followers

%d bloggers like this: