How can you efficiently tell if a word is a palindrome? You could always reverse your input, and then test that reversed String against your initial input String (because they'll be equal if the input is a palindrome, by definition). Or, you could use my Stack and do this.
Code Pretty Print Script
Thursday, December 12, 2013
Thursday, November 21, 2013
A Nicer Way to Sort
When you're dealing with production code, it's nice to have a convenient sort utility method that works with Arrays and Collections. I think you might find this class useful, especially if you can use import static!
Tuesday, November 19, 2013
Converting Strings to Wrapper Types
Are you dealing with a lot of numeric data stored in strings? Don't you wish there were some simple utility wrappers to use? Try these:
Monday, November 18, 2013
Swapping Without Temporary Storage
Can you swap values in place (without temporaries) in Java? Yes!
This classic technique continues to work.
This classic technique continues to work.
Sunday, November 17, 2013
Even-Odd Optimization
When you want to test whether something is even or odd, don't use the expensive modulo operation like this -
for (int i = 0; i < 100; ++i) { if (i % 2 == 0) { System.out.println("i = " + i + " is even."); } else { System.out.println("i = " + i + " is odd."); } }You should probably use this instead -
Saturday, November 16, 2013
Stack (Unbound)
Implementing an abstract data type like an unbounded Stack allows its' use with a two stack arbitrary precision machine. This Stack provides peek(), pop() and push().
Inspired by Dan's question on Stack Overflow.
Given this "program", the Stack will have one number at the top (i.e. 12).
Inspired by Dan's question on Stack Overflow.
Given this "program", the Stack will have one number at the top (i.e. 12).
( 3 * 4 ) .
Friday, November 15, 2013
Reflections
Subscribe to:
Posts
(
Atom
)