Two different apple id 's contacts sync together I have sign out my apple id and deleted my contacts then sign in my friend's apple id and merge his contacts.Then sign out his apple id.But the problem is when i have sign in my own appID,contacts were combined together.now our contacts are synced.i don't understand why this has happened and i don't want him to have my contacts.what should i do now???
You mentioned, "I have sign out my apple id and deleted my contacts then...", if you are sure about that, you don't have to worry about your friend getting your contacts. 

After your friend signing in their Apple ID on your phone, you or your friend probably might not select to delete the contacts after signing out from your device. That would be the reason that you can see your friend's contact. 

You can easily restore your contacts via iCloud (https://www.icloud.com/#settings).