Attempt at a sorting algorithm
Does my algorithm already have a name?


It's called counting sort.


  What are the downsides to it? (Other than it is really stupid to sort { 900000, 1 } with it.)


That's exactly the major disadvantage of the algorithm: it doesn't work well if the range of values is large.


  Why is it not a good solution in general?


Because it can sort only integers. You can't use it to sort floating point numbers, strings or any other type that doesn't behave as an integer.


  Any suggestions for optimization?


The condition if (tempArr[j] != 0) is completely useless. If you leave it out, the code will work exactly the same.