pastebin

Paste Search Dynamic
Recent pastes
printArray
  1. #include <sstream>
  2. #include <iostream>
  3. #include <type_traits>
  4. using namespace std;
  5.  
  6. template <class T>
  7. class Sorting {
  8. private:
  9.     static void printArray(T* start, T* end)
  10.     {
  11.         int size = end - start;
  12.         for (int i = 0; i < size; i++)
  13.             cout << start[i] << " ";
  14.         cout << endl;
  15.     }
  16.  
  17. public:
  18.     // TODO: Write your code here
  19.    
  20. static void sortSegment(T* start, T* end, int segment_idx, int cur_segment_total) {
  21.     int h = cur_segment_total;        
  22.     int n = end - start;    
  23.     int i, j;
  24.     for(i=h; i<n; i++){
  25.         T t = start[i];
  26.         for(j = i-h; j>=0 && t<start[j]; j=j-h)
  27.         start[j+h] = start[j];            
  28.         start[j+h] = t;        
  29.     }
  30. }
  31.  
  32. static void ShellSort(T* start, T* end, int* num_segment_list, int num_phases) {
  33.     for(int i=num_phases-1; i>=0; i--){
  34.         sortSegment(start, end, i, num_segment_list[i]);
  35.         printArray(start, end);        
  36.     }
  37. }
  38. };
  39. int main(){
  40.         int num_segment_list[] = {1, 3, 5};
  41.         int num_phases = 3;
  42.         int array[10] = { 10, 9, 8 , 7 , 6, 5, 4, 3, 2, 1 };
  43.  
  44.         Sorting<int>::ShellSort(&array[0], &array[10], &num_segment_list[0], num_phases);
  45.         return 0;
  46. }
Parsed in 0.017 seconds