text: In applications such as in radix sort, a bound on the maximum key value  will be known in advance, and can be assumed to be part of the input to the algorithm. However, if the value of  is not already known then it may be computed, as a first step, by an additional loop over the data to determine the maximum key value.
  The output is an array of the elements ordered by their keys. Because of its application to radix sorting, counting sort must be a stable sort; that is, if two elements share the same key, their relative order in the output array and their relative order in the input array should match.
  Pseudocode
  In pseudocode, the algorithm may be expressed as:
  function CountingSort(input, k)
  count ← array of k + 1 zeros
  output ← array of same length as input
  for i = 0 to length(input) - 1 do
  j = key(input[i])
  count[j] = count[j] + 1
  for i = 1 to k do
  count[i] = count[i] + count[i - 1]
  for i = length(input) - 1 down to 0 do
  j = key(input[i])
  count[j] = count[j] - 1
  output[count[j]] = input[i]
  return output
  Here input is the input array to be sorted, key returns the numeric key of each item in the input array, count is an auxiliary array used first to store the numbers of items with each key, and then (after the second loop) to store the positions where items with each key should be placed,