Array Sorting in C++ I have this simple implementation for array sorting:

#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;

using namespace std;

// some magic for the sorter
int compare(const void *i, const void *j) {
    int a = *(int *) i, b = *(int *) j;
    return a &lt; b ? -1 : a &gt; b ? 1 : 0;
}

int main() {
    int arr[100], temp = 0, count = 0;

    // reads values into the array (assumed integers as input)
    while (cin &gt;&gt; arr[count++]);
    count--;

    // what sorts the array
    qsort(arr, count, sizeof(int), compare);

    // prints everything but duplicate elements
    for (int i = 0; i &lt; count; i++) {
        bool match = false;
        for (int j = 0; j &lt; i &amp;&amp; !match; j++)
            if (arr[i] == arr[j])
                match = true;
        if (!match)
            cout &lt;&lt; arr[i];
    }
}


How can it be improved? I'd like to also remove duplicate elements rather than just silently ignoring them too.
You should use your standard libraries when you can. Consider that a std::set already does all the hard work, unique, and sorted values:

#include &lt;iostream&gt;
#include &lt;set&gt;

int main() {
    std::set&lt;int&gt; data;

    // reads values into the set (assumed integers as input)
    int val;
    while (std::cin &gt;&gt; val) {
        data.insert(val);
    }

    for(std::set&lt;int&gt;::iterator iter = data.begin(); iter != data.end(); ++iter) {
        std::cout &lt;&lt; (*iter) &lt;&lt; "\n";
    }

}


Note though, that the above implementation has horrible handling of issues that may come from invalid input. Still, the entire implementation is significantly simpler than yours.