I know that sharp gp2d12 and sharp GP2Y0A21YK0F is different in means of detection area, but my question is however i can use this library from arduino playground: (see link in next post)
you are of so great help if you help me with this project that has a tight deadline
Without taking a close look at the sensors you mention I would answer your question with a "yes, but".
The sketch simply reads a value from the ADC then applies a formula to that value in order to determine the distance.
There is no reason you can't use that method, BUT, the formula is likely to be different for the two sensors.
You should compare the datasheets for the two sensors to see what differences there are. IIRC they have graphs indicating the relationship between distance and output voltage. It is this relationship that the formula is trying to express.