Pagini recente » Cod sursa (job #1779506) | Cod sursa (job #2962211) | Cod sursa (job #1671686) | Cod sursa (job #1136586) | Cod sursa (job #1752773)
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
int* CreateVector(int n, int a, int b, int c);
void RadixSort(int n, int* list);
int main()
{
ifstream fin;
ofstream fout;
fout.open("radixsort.out");
fin.open("radixsort.in");
int n, a, b, c;
fin >> n >> a >> b >> c;
int* list = CreateVector(n, a, b, c);
RadixSort(n, list);
for(int i = 1; i <= n; i += 10)
{
fout << list[i] << " ";
}
fin.close();
fout.close();
return 0;
}
int* CreateVector(int n, int a, int b, int c)
{
int *list = new int[n + 1]();
list[1] = b;
for(int i = 2; i <= n; i++)
{
list[i] = ((1LL * a * list[i-1]) % c + b) % c;
}
return list;
}
void RadixSort(int n, int* list)
{
queue<int> queueList[257];
for(int j = 0; j < 4; j++)
{
for(int i = 1; i <= n; i++)
{
int byte = (list[i] >> (j * 8)) & 0xFF;
queueList[byte].push(list[i]);
}
int k = 1;
for(int i = 0; i < 257; i++)
{
while(!queueList[i].empty())
{
list[k] = queueList[i].front();
queueList[i].pop();
k++;
}
}
}
}