Maria Sharapova ended a two-game losing streak against fellow former world number one Ana Ivanovic, to reach the final of the China Open in Beijing.