本文整理汇总了C++中SortArray::size方法的典型用法代码示例。如果您正苦于以下问题:C++ SortArray::size方法的具体用法?C++ SortArray::size怎么用?C++ SortArray::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortArray
的用法示例。
在下文中一共展示了SortArray::size方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OddEvenSort
void OddEvenSort(SortArray& A)
{
bool sorted = false;
while (!sorted)
{
sorted = true;
for (size_t i = 1; i < A.size()-1; i += 2)
{
if(A[i] > A[i+1])
{
A.swap(i, i+1);
sorted = false;
}
}
for (size_t i = 0; i < A.size()-1; i += 2)
{
if(A[i] > A[i+1])
{
A.swap(i, i+1);
sorted = false;
}
}
}
}
示例2: SelectionSort
void SelectionSort(SortArray& A)
{
volatile ssize_t jMin = 0;
A.watch(&jMin, 3);
for (size_t i = 0; i < A.size()-1; ++i)
{
jMin = i;
for (size_t j = i+1; j < A.size(); ++j)
{
if (A[j] < A[jMin]) {
A.mark_swap(j, jMin);
jMin = j;
}
}
A.swap(i, jMin);
// mark the last good element
if (i > 0) A.unmark(i-1);
A.mark(i);
}
A.unwatch_all();
}
示例3: CombSort
void CombSort(SortArray& A)
{
const double shrink = 1.3;
bool swapped = false;
size_t gap = A.size();
while ((gap > 1) || swapped)
{
if (gap > 1) {
gap = (size_t)((float)gap / shrink);
}
swapped = false;
for (size_t i = 0; gap + i < A.size(); ++i)
{
if (A[i] > A[i + gap])
{
A.swap(i, i+gap);
swapped = true;
}
}
}
}
示例4: BubbleSort
void BubbleSort(SortArray& A)
{
for (size_t i = 0; i < A.size()-1; ++i)
{
for (size_t j = 0; j < A.size()-1 - i; ++j)
{
if (A[j] > A[j + 1])
{
A.swap(j, j+1);
}
}
}
}
示例5: CocktailShakerSort
void CocktailShakerSort(SortArray& A)
{
size_t lo = 0, hi = A.size()-1, mov = lo;
while (lo < hi)
{
for (size_t i = hi; i > lo; --i)
{
if (A[i-1] > A[i])
{
A.swap(i-1, i);
mov = i;
}
}
lo = mov;
for (size_t i = lo; i < hi; ++i)
{
if (A[i] > A[i+1])
{
A.swap(i, i+1);
mov = i;
}
}
hi = mov;
}
}
示例6: BinaryInsertionSort
// swaps every time (keeps all values visible)
void BinaryInsertionSort(SortArray& A)
{
for (size_t i = 1; i < A.size(); ++i)
{
value_type key = A[i];
A.mark(i);
int lo = 0, hi = i;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (key <= A[mid])
hi = mid;
else
lo = mid + 1;
}
// item has to go into position lo
ssize_t j = i - 1;
while (j >= lo)
{
A.swap(j, j+1);
j--;
}
A.unmark(i);
}
}
示例7: GnomeSort
void GnomeSort(SortArray& A)
{
for (size_t i = 1; i < A.size(); )
{
if (A[i] >= A[i-1])
{
++i;
}
else
{
A.swap(i, i-1);
if (i > 1) --i;
}
}
}
示例8: InsertionSort
// swaps every time (keeps all values visible)
void InsertionSort(SortArray& A)
{
for (size_t i = 1; i < A.size(); ++i)
{
value_type key = A[i];
A.mark(i);
ssize_t j = i - 1;
while (j >= 0 && A[j] > key)
{
A.swap(j, j+1);
j--;
}
A.unmark(i);
}
}
示例9: InsertionSort2
// with extra item on stack
void InsertionSort2(SortArray& A)
{
for (size_t i = 1; i < A.size(); ++i)
{
value_type tmp, key = A[i];
A.mark(i);
ssize_t j = i - 1;
while (j >= 0 && (tmp = A[j]) > key)
{
A.set(j + 1, tmp);
j--;
}
A.set(j + 1, key);
A.unmark(i);
}
}
示例10: ShellSort
void ShellSort(SortArray& A)
{
size_t incs[16] = { 1391376, 463792, 198768, 86961, 33936,
13776, 4592, 1968, 861, 336,
112, 48, 21, 7, 3, 1 };
for (size_t k = 0; k < 16; k++)
{
for (size_t h = incs[k], i = h; i < A.size(); i++)
{
value_type v = A[i];
size_t j = i;
while (j >= h && A[j-h] > v)
{
A.set(j, A[j-h]);
j -= h;
}
A.set(j, v);
}
}
}
示例11: QuickSortTernaryLL
void QuickSortTernaryLL(SortArray& A)
{
return QuickSortTernaryLL(A, 0, A.size());
}
示例12: QuickSortTernaryLR
void QuickSortTernaryLR(SortArray& A)
{
return QuickSortTernaryLR(A, 0, A.size()-1);
}
示例13: MergeSort
void MergeSort(SortArray& A)
{
return MergeSort(A, 0, A.size());
}