⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e20-04.cpp

📁 游戏开发数据结构Data Structures for Game Programmers
💻 CPP
字号:
// =======================================================
//  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -