|
| |
HyperShadow0213
|
C++ Programming help |
|
I need some help in C++ programming, if anyone is proficient in it.
I have to figure out four sorting algorithms: Bubble, insertion, merge, and radix sorting. I've figured out the first three, but radix is giving me a lot of problems. Basically, it's to compare running times with each sort. But just figuring out the algorithm for radix is giving me a problem. I know you can do it with queues, but we haven't learned that yet. So, I'm doing it with arrays, which is a lot harder. If you don't know what radix sorting is, say you have a list of 6 numbers: 536 391 889 613 119 307 535 What radix sorting with do, is look at the first number first, then sort accordingly. So it'll look at the 5,3,8,6,1,3,5 and put them in order. So after the first run, it'll look like this: 119 391 307 536 535 613 889 Now that still isn't in order. So the second run through, it'll take all the numbers with 1, look at THEIR second number, and sort accordingly. After that is done, it'll look like this: 119 307 391 536 535 613 889 Still out of order, since the 500 numbers are messed up. Radix sort still needs to look at the third digit, then plan accordingly. So the final result will end in a sorted list. tldr; radix sorting is basically like putting things in alphabetical order. Now I tried out some code that will work. My algorithm will start at the last number first then work its way towards to first number, using three arrays. Here's my code so far. It compiles and runs without any errors, but my result is all 0's and I don't know why. int radixsort( long int array[], long int n){ int k, i, j, m; float p; for(p=0;p<=1;p++){ for(m=0;m<n;m++){ temp[m]=(array[m]/(int)pow(10,p));} for(j=0;j<n;j++){ for(k=-9;k<=9;k++){ for(i=0;i<n;i++){ if(((temp[i])%10)==k) {sorted[j]=temp[i];} } } } for(m=0;m<n;m++){ array[m]=sorted[m];} } } If you can figure out why it's giving me 0s, please tell me.I appreciate any help | |
quote quick quote edit quick edit del posts in thread report
| |
Devastate
|
re: C++ Programming help |
|
------------------- “You're only given a little spark of madness. You mustn't lose it.” - Robin Williams
| |
quote quick quote edit quick edit del posts in thread report
| |
| [All dates in (PT) time] | Threads List « Next Newest Next Oldest » |
Powered by neoforums v0.9.8 RC2 (equilibrium)
Copyright Neo Era Media, Inc. 1999-2009