package cal;

import java.util.ArrayList;
import java.util.Stack;

public class AffixConverter {
	/**
	 * Convert infix to postfix expression: 1*(22+3.33) -> 1 22 3.33 + *
	 * 
	 * Input: ArrayList<String>  ["1","*","(","22","+","3.33",")"]
	 * Output: ArrayList<String>  ["1","22","3.33","+","*"]
	 *
	 * @param ArrayList of a infix expression
	 * @return ArrayList of a postfix expression
	 */
	public static ArrayList<String> toPostfix(ArrayList<String> arrayList) {
		ArrayList<String> postfix = new ArrayList<String>();
		Stack<String> operatorStack = new Stack<String>(); // stack to hold
															// symbols
		operatorStack.push("#"); // symbol to denote end of stack
		for (int i = 0; i < arrayList.size(); i++) {
			String currentChar = arrayList.get(i);
			// if a operator repeatedly pops if stack top has same or higher
			// precedence
			if (BasicMathsMethods.isOperator(currentChar)) {
				while (BasicMathsMethods.comparePriority(currentChar, operatorStack.peek()))
					postfix.add(operatorStack.pop());
				operatorStack.push(currentChar);
			}
			// push if left parenthesis
			else if (currentChar.equals("("))
				operatorStack.push(currentChar);
			else if (currentChar.equals(")")) {
				// repeatedly pops if right parenthesis until left parenthesis
				// is found
				while (!operatorStack.peek().equals("("))
					postfix.add(operatorStack.pop());
				operatorStack.pop();
			} else
				postfix.add(currentChar);
		}
		// pops all elements of stack left
		while (!operatorStack.peek().equals("#")) {
			postfix.add(operatorStack.pop());
		}

		return postfix;
	}
}

@@ -60,16 +60,111 @@
 Stack;%0A%0A
+/**%0A * This class handles the conversion between difference affix.%0A * %0A * @author Jason Yu%0A */%0A
 public c
@@ -264,21 +264,29 @@
 + *%0A%09 * 
+%3Cul%3E
 %0A%09 * 
+%3Cli%3E
 Input: A
@@ -297,25 +297,24 @@
 List%3CString%3E
- 
  %5B%221%22,%22*%22,%22(
@@ -340,16 +340,20 @@
 )%22%5D%0A%09 * 
+%3Cli%3E
 Output: 
@@ -369,17 +369,16 @@
 %3CString%3E
- 
  %5B%221%22,%222
@@ -403,19 +403,58 @@
 %0A%09 *
-%0A%09 * @param
+ %3C/ul%3E%0A%09 * %0A%09 * @param arrayList%0A%09 *            an
  Arr
@@ -1101,17 +1101,23 @@
 entChar,
- 
+%0A%09%09%09%09%09%09
 operator

Add more comment to AffixConverter