so i basically looked at some pseudo code and tried to code it but when i run it i get like one number out of order, any idea?
Code:#include <iostream> using namespace std; #define NUMBER_OF_ELEMENTS 15 int main(){ int toSort[NUMBER_OF_ELEMENTS]; cout<< "Enter the numbers:\n "; for (int i = 0; i < NUMBER_OF_ELEMENTS; i++){ cout<< "\n\t"; toSort[i] = rand(); } bool sorting = true; do{ int total = 0; for(int b = 0; b <= NUMBER_OF_ELEMENTS; b++){ if(toSort[b + 1] < toSort[b]){ int tmp = toSort[b]; toSort[b] = toSort[b + 1]; toSort[b + 1] = tmp; } else{ total++; } } if (total >= NUMBER_OF_ELEMENTS){ sorting = false; } } while(sorting == true); cout<<"Everything sorted:"; for (int z = 0; z < NUMBER_OF_ELEMENTS; z++){ cout<<"\n\t"; cout<<toSort[z]; } }