Professional Documents
Culture Documents
2 * HackerRank link:
3 * Title:hw7_1.cpp
/*
2 * HackerRank link:
3 * Title:hw7_1.cpp
4 * Abstract: Conducts the radix sort
5 * Author: Marcus Gonzalez
iostream>
#include <
#include < vector>
#include <cmath>
using namespace std;
class Graph
{
public:
int vertex;
int size;
vector<int> nodes;
Graph(){
size = 0;
}
int getChildCount(){
return size;
}
void c lear(){
nodes.clear();
size = 0;
}
};
int getDigitCount(int digit){
int count = 0;
while(digit){
digit /= 10;
++count;
}
return count;
}
int m ain () {
int size = 0 ;
int input = 0;
int largestDigit = 0;
nt index = 0;
i
Graph temp[10];
vector<int> arr;
cin >> size;
for(int i = 0; i < size; i++){
cin >> input;
if(input > largestDigit)
largestDigit = input;
arr.push_back(input);
}
largestDigit = getDigitCount(largestDigit);
for(int i = 0; i < largestDigit; i++){
for(int j = 0; j < size; j++){//place numbers in respective indexes
if((i+1) > getDigitCount(arr[j]))
index = 0;
else
index = int(arr[j] / pow(10,i)) % 10;
temp[index].append(arr[j]);
}
arr.clear();
for(int k = 0;k < 10; k++){
for(int l = 0; l < temp[k].getChildCount();l++){
arr.push_back(temp[k].nodes[l]);
}
temp[k].clear();
}
for(int m = 0
; m < size; m++)
cout << a rr[m] << " ";
cout <<"\n";
}
return 0;
}