java stack infix to postfix


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: java stack infix to postfix

  1. #1
    Join Date
    Nov 2005
    Posts
    10

    java stack infix to postfix

    this is supposed to convert expressions using a stack
    like "6 + 2.1 * 4.2"
    becomes something like
    " 6 2.1 4.2 *+"

    protected String toPostFix ()
    {
    StackB x = new StackB ();
    String op = "+-*/%^";
    String post = "";
    StringTokenizer t = new StringTokenizer (s, " ");
    String theToken = "";
    while (t.hasMoreTokens ())
    {
    System.out.println ("im into#1 there!");
    theToken = t.nextToken ();
    System.out.println ("the token is:" + theToken);
    if (op.indexOf (theToken) >= 0)
    {
    while (!x.empty () && higher (x.peek (), theToken))
    {
    System.out.println ("im into #2here!");
    x.push (theToken);
    theToken=x.pop();
    // post += x.pop ();
    System.out.println (x.top);
    post += theToken;

    }

    }

    else
    {
    post += theToken;
    //to postfix ... "3 + 5.2 * -8.72"
    }
    System.out.println (post);
    while (!(x.empty ()))
    {
    theToken = x.pop ();
    post += theToken;
    System.out.println ("im in!");
    // post += " " + theToken + " ";

    }
    }


    return post;
    }

  2. #2
    Join Date
    Aug 2005
    Location
    Melbourne...Australia
    Posts
    279
    And what is happening with it mate??

    BTW you should use code tags..

Similar Threads

  1. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  2. Infix to Postfix
    By arvinp in forum Java
    Replies: 0
    Last Post: 03-05-2005, 11:40 PM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 02:57 PM
  4. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center