c++ - Does anyone know if this sorting algorithm already exists? -


this sorting code ("think") came with. wondering if exists.....

it consists of going through array comparing values of array highest value found until moment, of same array.

if value of array higher value of variable, value o variable becomes value of array, if not, values swapped.

any suggestions improve code, runtime measurements welcome. way, it's on c++.

#include <iostream> using namespace std;  unsigned int counter = 0; unsigned int buck[] = {52,36,45,10,2,5,8,14,63,11}; unsigned int aux = buck[0]; unsigned int mem = 0;  int main() {  /* next loop repeat code x times; x size of       matrix*/  (counter = 0; counter < 10; counter++){  /*  code compare aux variable list item, if higher, performs swap, if not exchange values, , go on comparisons*/      (int i=0; i<9;i++){             aux=buck[i];         if (aux < buck[i+1]){             aux=buck[i+1];             continue;         }         else{             mem=buck[i+1];             buck[i+1]=aux;             buck[i]=mem;         }     } }     (counter = 0; counter < 10; counter++){   cout << buck[counter] << " | "; } cout<<endl; return 0; } 

this bubble sort, although aux=buck[i+1] redundant, , indeed aux well. more succinct version be:

for (counter = 0; counter < 10; counter++){     (int i=0; i<9;i++){         if (buck[i] > buck[i+1]){             mem=buck[i+1];             buck[i+1]=buck[i];             buck[i]=mem;         }     } } 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -