The primary problem is here:
while (x >! k)
On the first iteration, the condition checks whether (0 > !k)
, and k
is not 0, so !k
is 0, so the condition is false and the loop never executes. Try using:
for (int x = 0; x < k; x++)
cout << array1[x] << "\n";
You also have a problem in the sort phase of your bubble sort; you only iterate through the data once, which is not enough to sort it, in general.
Finally, some design issues.
- You should have one function to sort the data and a separate function to print it. Don't combine the two functions as you have done here.
- Avoid global variables. Pass the array and its operational length to the sort function, and to the print function if you have one.