Two masses m1 and m2 having initial velocities u1 and u2 respectively collide directly.
After collision, the final velocities of masses m1 and m2 are v1 and v2 respectively.
The total momentum before collision
= mlul + m2u2
and the total momentum after collision
= m1v1 + m2v2
According to the law of conservation of momentum we can write,
m1u1 + m2u2 = m1v1 + m2v2
( Note that u1, 112, v1 and v2 are having direction towards positive x).