-2
我正在寫一個程序,它接受一個整數數組並將它們排序爲基數16 8 10和2.我的函數適用於除2之外的所有基數。它不能正確地對數字進行排序。我一直在環顧四周,沒有地方特別解釋這個問題。我認爲即時通訊應該使用移位(>> < <),但我不知道如何?基數2的基數排序功能不起作用?
void Sortfunc(int myarray[], int n, int base){
queue<int> bins[10];
int MAX=4; // max digits
int COUNTER=0;// position of counter
while (COUNTER < MAX) {
for(int i=0; i<n; i++){// sorts array by digit
int dividor=pow(base,COUNTER);
int temp = myarray[i];
int value = static_cast<int>((temp/dividor)%10); //gets the decimal
bins[value].push(temp);
}
沒有看到你的代碼我不認爲我們可以給你很多建議。你能發佈你有什麼和你得到的具體錯誤嗎? – templatetypedef
我得到的錯誤是,當我輸入基數2時,數組沒有正確排序。對於所有其他基數工作正常。 – G3Spin
是否有任何理由你不會使用'std :: sort'? –