Why is it showing segmentation fault.. Pls correct my mistakes

You have not put the return statement in if condition.

If I put the return Its running and showing no output .but if I interchange both rec statements I am getting abcd abd … So how can I get output in correct order?

Put them in a set to store in lexiographical order