BAE Systems Interview Question

Write an algorithm to ensure parentheses are matched in a string.