Computer HardwareXbox GamesGameCubePlaystation 2PSOnePC/Windows GamesGameboy AdvanceDreamcastNintendo 64Gameboy ColorNintendo DSSony PSPXbox 360Nintendo Wii GamesPS3 Games

Neoseeker Forums » Special Interest » Academia » Homework & Tutoring » C++ Programming help

REPLY TO THIS THREAD   START NEW THREAD
| Sharemore
Options: Print   subscribe   remove   PM this thread to a friendNeoPM  
subscribe to thread Topic: C++ Programming help
HyperShadow0213
[AoC]Unite!
true seeker (2K Remix)



HyperShadow0213's profileHyperShadow0213's neohomeNeoPM HyperShadow0213HyperShadow0213's gallery (1 images)
total posts: 2141
since: Feb 2003
Nov 08, 09 at 3:23am
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  searchposts in thread  report
Devastate
unwashed heathen
(moderator)

Action [PSP]



Devastate's profileEmail DevastateNeoPM Devastate
total posts: 892
since: Jul 2009
Nov 08, 09 at 11:48am
re: C++ Programming help

Btw, we have a Programming Forum. It would be wise to post this in there too.



-------------------
“You're only given a little spark of madness. You mustn't lose it.” - Robin Williams
quote   quick quote   edit   quick edit   del  searchposts in thread  report
[All dates in (PT) time]Threads List   « Next Newest   Next Oldest »
REPLY TO THIS THREAD   START NEW THREAD


search:
search posts by username:
Neoseeker Forums » Special Interest » Academia » Homework & Tutoring » C++ Programming help



Jump to another forum:

Powered by neoforums v0.9.8 RC2 (equilibrium)
Copyright Neo Era Media, Inc. 1999-2009

neoseeker forum community
Neoseeker.com   |   Forum Rules   |   Forum FAQ   |   Neoseeker Terms of Use   |   Supermods On Duty [ server id: nova ··· elapsed: 0.0666379929]
Affiliated sites:   GameGrep - Football Manager Wiki - Halo Wiki - MGS Wiki - GTA Wiki - Smackdown Wiki - Zelda Wiki - PS2seeker - Xbox seeker - DEVPEN - GFXcess