40. Implement Queue by 2 Stacks

Leave a comment

August 24, 2016 by oneOokay

 

40. Implement Queue by 2 Stacks

2个stack:s1和s2:s1用来存正常的Queue.add(); s2用来存s1pop出来的数;s2若不为空,则当Queue.pop()时,应该从s2中pop;若s2为空,将s1中元素倒入s2中,再pop;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: