Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > polish stack

Reply
Thread Tools

polish stack

 
 
Chronic Philharmonic
Guest
Posts: n/a
 
      05-10-2008


"Kenneth P. Turvey" <(E-Mail Removed)> wrote in message
news:4825a40a$0$30073$(E-Mail Removed). com...
> On Sat, 10 May 2008 12:08:56 +0000, Joshua Cranmer wrote:
>
>> Polish or reverse-polish notation (the latter tends to be more commonly
>> used) is better for computers to work with than infix notation, because
>> it doesn't requires parenthesis to operate, and because computation is a
>> simple stack-based algorithm.

> [Snip]
>
> Not just computers. I like my calculators to work this way. It really
> is much easier once you get used to it.


Yup. I never use the parenthesis on infix notation calculators because I
never can seem to match the open-parens with the close-parens. Whenever I
have serious mathematical calculation to do, I get out my trusty HP11, or my
HP32S II.


 
Reply With Quote
 
 
 
 
Chronic Philharmonic
Guest
Posts: n/a
 
      05-11-2008


"Lew" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> Kenneth P. Turvey wrote:
>> On Sat, 10 May 2008 12:34:51 -0400, Arne Vajh°j wrote:
>>
>>> Something in time could be changed, but other characteristics is given.
>>> A day is the time it takes the earth to rotate around itself. A year is
>>> the time it takes the earth to rotate around the sun. We can't tell the
>>> earth to male that 1000 days per year instead of those 365.25 !

>>
>> That's certainly true, but does it really make sense for us to have 24
>> hour days, 60 minute hours and 60 minute seconds? Why not 10 hour days,
>> 10 minute hours, and 10 second minutes or something similar? Do we
>> really need every day to start at the same time anymore? It is certainly
>> convenient, but is there another way to get that convenience without
>> screwing up our units of measure? Couldn't days just be fractions of a
>> year, which is what they really are anyway. I don't know. It just seems
>> like people just decided to ignore time when they developed the metric
>> system.

>
> Sixty is a better number base than ten anyway. We should use
> sexagintesimal (exekontesimal?) arithmetic for everything.


That's a lot of symbols to keep track of. Even our alphabet has only 26,
give or take a few. While the Chinese alphabet has more discrete symbols,
but they aren't exactly distinct in the same way as Western symbols are.


 
Reply With Quote
 
 
 
 
mamling@gmail.com
Guest
Posts: n/a
 
      05-12-2008
On May 10, 5:49*pm, "Kenneth P. Turvey" <(E-Mail Removed)>
wrote:
> That's certainly true, but does it really make sense for us to have 24
> hour days, 60 minute hours and 60 minute seconds? *Why not 10 hour days,
> 10 minute hours, and 10 second minutes or something similar? *
>
> Do we really need every day to start at the same time anymore? *It is
> certainly convenient, but is there another way to get that convenience
> without screwing up our units of measure? *Couldn't days just be
> fractions of a year, which is what they really are anyway. *
>
> I don't know. *
>
> It just seems like people just decided to ignore time when they developed
> the metric system.


At the time of the French revolution, when the metric system was
invented, France for a while (The last vestiges were abandoned in
1805.) went to 10 hours per day, 100 minutes per hour and 100 seconds
per minute. The resulting second, with 100,000 of them from noon to
noon, was a little shorter than the conventional second (86,400
seconds from noon to noon). There were also 12 metric months per year,
3 weeks per month, 10 days per week.

--Mike Amling
 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-18-2008
Please help me.
At least how do you get to (the rest is obvious)
> 2 3 5 * +

.... and I didn't find something on the internet.

I whould like whether you can lead me to some source, please.

Thanks )


 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-18-2008
Also,
I need explain what is the representation of (for example) ;
9+3+4*5-2 ?

Thanks


 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-18-2008
Mr. X. wrote:
> I need explain what is the representation of (for example) ;
> 9+3+4*5-2 ?


9 3 + 4 5 * + 2 -

Arne
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      05-18-2008
Mr. X. wrote:
> Please help me.
> At least how do you get to (the rest is obvious)
>> 2 3 5 * +

> ... and I didn't find something on the internet.
>
> I whould like whether you can lead me to some source, please.


I think your Google is broken.

Mine has 32000 hits on:

convert infix postfix

Arne
 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-18-2008
Hi,

I don't have book of polish-stack, and I won't buy any,
If you don't want to answer - please, don't answer at all.
I just want to know the concept in details !
I have tried a lot searching google, but it seems that I found my own
questions,
or answers that are after the transform to 95+ ... (and not 9 + 5)

1. How do I get it from 9+3+4*5-2 to any kind of : 9 3 + 4 5 * + 2 - ?
--- > I suppose, the concept is to run from left to right arguments,
put values to stack, and put operator to stack, but if current operator's
priority is higher then previous,
then wait it to be put at the next step.
so for 9 + 3 + 4 * 5, the sequence is 9, 3, + (now 4 has * operator which
its priority is higher, so I wait ...),
ten 4,5,* ... (something like that ...).
I didn't see any clue of that algorithm, so I suppose that's right (Is that
true ?)
2. Any free java code somewhere of that algorithm, it will be fine.

Thanks


 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-18-2008
....
Also, what I think (only guess) :
there are two stacks :
1 - stack of arguments (let call it : SA)
2 - stack of operators (let call it : SO).

We always push on stack.
We pop from stack, only at end of formula, or when we reach an operator at
the same priority or less then current priority.
The 1st 2nd arguments are operated by the 1st argument.
When pop from stack - we pop from the last argument of the stack (LIFO).

9+3+4*5-2

SA:9
SO:<empty>

SA:9
SO:+

SA:9,3
SO:+

(there is no another operand, so we keep pushing on stack).

SA:9,3
SO:+,+

(now we can pop the lasts : 9,3 with +, and push the result again into
stack)

SA:12
So:+

SA:12,4
SO:+

(there is no next argument, so we're keep trying).

SA:12,4
SO:+,*

SA:12,4,5
SO:+,*

SA:12,4,5,
SO:+,*,-

(now the priority is downed so we pop the last arguments : 4,5, with
corresponding operator : *, and push back to stack).

SA:12,20
SO:+,-

SA:32
SO:-

SA:32,2
SO:-

<end>
SA:30
SO:<empty>

Stack is empty, so we pop the result on argument : SA.
result = 30 !

The same thing can be for brakes "(" with a higher priority no. (I can mark
for each element it's priority, by some kind of method :
when priority get higher, I increment the priority counter, when it getting
lower I decrement the priority counter, and every time, and due that I know
how can I handle the stack as I have described above.

Is the above right thorey ?
If the above is right, I think I'll mange...

Thanks


 
Reply With Quote
 
Mr. X.
Guest
Posts: n/a
 
      05-18-2008
No, No !!!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does std::stack::pop() not throw an exception if the stack is empty? Debajit Adhikary C++ 36 02-10-2011 08:54 PM
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
stack frame size on linux/solaris of a running application stack Surinder Singh C Programming 1 12-20-2007 01:16 PM
Why stack overflow with such a small stack? Kenneth McDonald Ruby 7 09-01-2007 04:21 AM
"stack level too deep"... because Threads keep their "starting" stack Sam Roberts Ruby 1 02-11-2005 04:25 AM



Advertisments