StudentMain.java - public class StudentMain private static <T> void print(Stack<T> st System.out.println if(st = null System.out.println"null else

StudentMain.java - public class StudentMain private static...

This preview shows page 1 - 2 out of 2 pages.

public class StudentMain { private static <T> void print(Stack<T> st) { System.out.println("------------"); if (st == null) { System.out.println("null"); } else if (st.empty()) { System.out.println("Empty stack"); } else { Stack<T> ts = new LinkedStack<T>(); while (!st.empty()) { T e = st.pop(); System.out.println(e); ts.push(e); } while (!ts.empty()) { st.push(ts.pop()); } } System.out.println("------------"); } private static void testInFixExp() { } public static void main(String[] args) { // Postfix { String exp = "3 5 + 4 4 - /"; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); print(pfe.evaluate(6)); } { String exp = "3 5 + 4 4 - /"; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); print(pfe.evaluate(7)); } { String exp = "3 5 + 4 2 - *"; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); System.out.println("Error at: " + pfe.validate()); } { String exp = "3 5 + 4 4 - /"; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); System.out.println("Error at: " + pfe.validate()); } { String exp = "3 5 + 4 2 -"; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); System.out.println("Error at: " + pfe.validate()); } { String exp = "3 5 + 4 2 - >="; PostFixExp pfe = new PostFixExpImp(); pfe.setExp(exp); InFixExp ife = pfe.toInFix();
Image of page 1

Subscribe to view the full document.

System.out.println(ife.getExp()); } // Infix { String exp = "3 - 2";
Image of page 2

Unformatted text preview: InFixExp ife = new InFixExpImp(); ife.setExp(exp); Pair&lt;Stack&lt;Integer&gt;, Stack&lt;String&gt;&gt; res = ife.evaluate(4); print(res.first); print(res.second); } { String exp = &quot;3 - 2&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); Pair&lt;Stack&lt;Integer&gt;, Stack&lt;String&gt;&gt; res = ife.evaluate(3); print(res.first); print(res.second); } { String exp = &quot;( 3 - 2 )&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); Pair&lt;Stack&lt;Integer&gt;, Stack&lt;String&gt;&gt; res = ife.evaluate(6); print(res.first); print(res.second); } { String exp = &quot;( 3 - 2 ) * ( 5 % 3 ) &gt;= ( ( 4 + 2 ) )&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); Pair&lt;Stack&lt;Integer&gt;, Stack&lt;String&gt;&gt; res = ife.evaluate(20); print(res.first); print(res.second); } { String exp = &quot;( 3 - 2 ) * ( 5 % 3 ) &gt;= ( ( 4 + 2 ) )&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); Pair&lt;Stack&lt;Integer&gt;, Stack&lt;String&gt;&gt; res = ife.evaluate(20); System.out.println(ife.toPostFix().getExp()); } { String exp = &quot;3 - 2 ) + 5&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); System.out.println(&quot;Error at: &quot; + ife.validate()); } { String exp = &quot;( 3 - 2 ) * 4 / 2 )&quot;; InFixExp ife = new InFixExpImp(); ife.setExp(exp); System.out.println(&quot;Error at: &quot; + ife.validate()); } } }...
View Full Document

  • Spring '13
  • james joshi

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes