Optimized Compact Finite Difference Schemes for Solving Wave Equations