Advertisement
SwordPencil

insertionsorter.cpp

Dec 28th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include "headlines.h"
  2.  
  3. Stats InsertionSorter::SortArray(long * arrayToSort, unsigned length)
  4. {//Сортировка вставками
  5.     Stats insertReport("Вставки");
  6.     this->SetTempArray(arrayToSort, length);
  7.     for (unsigned i = 0; i < length; i++)
  8.     {
  9.         insertReport.compareCount++;
  10.         for(int j = i; j > 0 && this->tempArray[j] < this->tempArray[j - 1];  j--)
  11.         {
  12.             insertReport.swapCount++;
  13.             swap(this->tempArray[j], this->tempArray[j - 1]);
  14.         }
  15.     }
  16.     ShowArray(tempArray, length);
  17.     return insertReport;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement