insertion sort using pattern matching