-
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;
}
-
And what is happening with it mate??
BTW you should use code tags..
Similar Threads
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
Replies: 0
Last Post: 03-05-2005, 11:40 PM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By Mike Tsakiris in forum .NET
Replies: 11
Last Post: 10-04-2002, 05:32 PM
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks