Implementation for counting the number of occurances of an element in a sorted array.