程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 幾種排序算法 C++

幾種排序算法 C++

編輯:C++入門知識

SortAlgorithm.h

#include <vector>
  =  swap( &,  & insertSort();                     
     selectSort();                    
     mergeSort();                    
     bubbleSort();                  
     quickSort(   ,   );     
    
     partition(  ,  sortSubVector( ,  merge( ,  ,  , <  ><  >

 

SortAlgorithm.cpp

 

#include <iostream><cstdlib> 
#include <ctime> 
#include <algorithm> 
#include  
 = ( vectorSize >  ? vectorSize :  ); 
    srand( time(  ) ); 
     (  i = ; i < size; i++ + rand() %  ); 
=( next = ; next < size; next++= moveItem =((moveItem > ) && (temp[moveItem - ] >= temp[moveItem - --= loop = size - ( i = ; i < loop; i++=( j = i + ; j < size; j++(temp[j] <=, size -  comp; 
        swapCheck = ; 

     (  pass = ; pass < size && swapCheck; pass++= ; 
         ( comp = ; comp < size - pass; comp++
             ( temp[ comp ] > temp[ comp + + = 

    } 
 SortAlgorithm::quickSort( first,  ( first >== partition( first, last ); 
   quickSort( first, currentLocation -  ); 
   quickSort( currentLocation + , last ); 
} 
 SortAlgorithm::partition(  left,  position =
    ( 
       ( temp[ position ] <= temp[ right ] && position !=-- ( position == ( temp[ position ] >=
       ( temp[ left ] <= temp[ position ] && left !=++ ( position == ( temp[ left ] >=
   } 
} 

 SortAlgorithm::sortSubVector( low, ((high - low) >=  middle1 = (low + high) /  middle2 = middle1 + 

 SortAlgorithm::merge( left,  middle1,  middle2,  leftIndex = rightIndex = combinedIndex =<>

    (leftIndex <= middle1 && rightIndex <=(temp[leftIndex] <=++] = temp[leftIndex++++] = temp[rightIndex++(leftIndex ==(rightIndex <=++] = temp[rightIndex++(leftIndex <=++] = temp[leftIndex++( i = left; i <= right; i++= SortAlgorithm::swap( &x,  &===( i = ; i < size; i++<<   <<((i + ) %  == <<<<=

 

main.cpp

 

#include <iostream> 
#include 
 << >><< << << << << , num - << 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved