insertInList function

This is an internal function that inserts in vector or list