title: Bubble Sort Optimization C++
body: <p>I was just practising a little bit and tried to sort an array with the bubble sort algorithm.
  Compiler didn't give me any warnings nor errors and it worked well! First you type 10 times a number and then the program sorts them + prints them.    </p>
  
  <p>Code:     </p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void arr_sort(int* array, const int arr_size){
  
  int temp = 0;   //Temporary integer to store (if necessary) the current element
  int end = 0;    //Run time condition
  
  while(end++ != arr_size){ // Will loop max. 10 times
  
      for(int i = 0; i &lt; arr_size; i++){
  
          if(array[i] &gt; array[i + 1]){    //If the current element 
              temp = array[i];    //is bigger than the next
  
              array[i] = array[i + 1];//Change the positions
              array[i + 1] = temp;    
          }
      }
  }
  
  }
  
  int main(){
  
  int arr_input[10];
  
  for(int i = 0; i &lt; 10;i++)      //The user has to type 10 numbers
      cin &gt;&gt; arr_input[i];        //which will be stored in this array
  
  arr_sort(arr_input, 10);        //sorts the array
  
  cout &lt;&lt; endl &lt;&lt; endl;
  
  for(int i = 0; i &lt; 10; i++)     //Print out the array!
      cout &lt;&lt; arr_input[i] &lt;&lt; ", ";
  cout &lt;&lt; endl;
  
  return 0;
  }
  </code></pre>
  
  <p>My only problem is the while-loop in the arr_sort function. I mean it sorts the array until <strong>end</strong> has the same value as <strong>arr_size</strong>. But often it doesn't need that long. My question now... How can I improve this function? How can I test if the array is completely sorted so the while-loop can stop without running another time and another time ...?</p>