Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Optimized Bubble Sort

void bubbleSort(int *arr, int n)
{
    for(int i=0; i<n; i++)
    {
      bool flag = false;
       for(int j=0; j<n-i-1; j++)
       {
          if(array[j]>array[j+1])
          {
            flag = true;
             int temp = array[j+1];
             array[j+1] = array[j];
             array[j] = temp;
          }
       }
      // No Swapping happened, array is sorted
      if(!flag){
         return;
      }
   }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: infinite loop c++ 
Cpp :: Unsorted Linked list in c++ 
Cpp :: c++ evaluate expression 
Cpp :: std distance c++ 
Cpp :: c++ map loop through key value 
Cpp :: c++ declaring and initializing strings 
Cpp :: counting sort c++ 
Cpp :: qt disable resizing window 
Cpp :: how to copy one vector to another 
Cpp :: adding elements to a vector c++ 
Cpp :: c++ functions 
Cpp :: http.begin() error 
Cpp :: c++ hide show console 
Cpp :: string vector c++ 
Cpp :: struct and array in c++ 
Cpp :: how print fload wiht 2 decimal in c++ 
Cpp :: convert binary string to int c++ 
Cpp :: find in string c++ 
Cpp :: segmented sieve of Eratosthenes in cpp 
Cpp :: overload stream extract cpp 
Cpp :: string to char* 
Cpp :: coordinate in 1d array 
Cpp :: c++ get type name of object 
Cpp :: reverse function in cpp string 
Cpp :: c++ vector initialization 
Cpp :: c++ array size 
Cpp :: c++ string to int 
Cpp :: c++ average 
Cpp :: detect cycle in an undirected graph 
Cpp :: sleep in c++ 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =