e20-04.cpp
来自「游戏开发数据结构Data Structures for Game Program」· C++ 代码 · 共 57 行
CPP
57 行
// =======================================================
// Chapter 20, Example 4
// The Radixsort
// =======================================================
#include "Array.h"
#include "Sorts.h"
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
template<class DataType>
void PrintArray( Array<DataType>& p_array )
{
int index;
for( index = 0; index < p_array.Size(); index++ )
{
cout << p_array[index] << ", ";
}
}
void main()
{
Array<int> array( 16 );
int index;
// seed the randomizer, see Chapter 22.
srand( time(0) );
// fill up the arrays with random values
for( index = 0; index < 16; index++ )
{
// 0-255
array[index] = rand() % 256;
}
RadixSort2( array, 8 );
cout << "Integer Array: ";
PrintArray( array );
cout << endl;
RadixSort4( array, 4 );
cout << "Integer Array: ";
PrintArray( array );
cout << endl;
RadixSort16( array, 2 );
cout << "Integer Array: ";
PrintArray( array );
cout << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?