Array Sorting in C++
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.