PDA

View Full Version : Help With a Project


Arcane_Disciple
09-22-2002, 03:16 PM
I have to write a program that checks a string containg a pile of coins. (p=penny, n-nickel, etc.) Say the user enters "pnqdpd". My function is supposed to check that string and see that the dime is the smallest, then calls a flip function that flips the pile so that the pile now has the dime on top. It will then check again until it comes to the penny and so on and so forth until everything is in the proper size order. What is the easiest way to do this?

sans-hubris
09-22-2002, 04:23 PM
I'm not going to give you the answer (and I would suggest that no one else do so either), but here are some hints:

Give your program the ability to understand the size of each coin.

Once you've done that, write a simple sort function (from the sound of it, you need to write a bubble sort function.)

Arcane_Disciple
09-22-2002, 05:04 PM
thanks for the suggestion. I don't want anyone to give an answer either. I was just trying to figure out the best way of sorting.

kmj
09-22-2002, 11:22 PM
I'm sorry, but I don't really understand what you're trying to do...

"My function is supposed to check that string and see that the dime is the smallest, then calls a flip function that flips the pile so that the pile now has the dime on top..."

what do you mean, flips the pile? See that the dime is the smallest? You mean, make sure there is no pennies or nickels in it?

Strike
09-23-2002, 01:10 PM
sounds like he's trying to describe a bubble sort to me ...

LonelyKing
09-23-2002, 09:35 PM
Yeah, that's all it is.

Arcane_Disciple
09-23-2002, 11:34 PM
actually its harder than i make it out to be. the prof told us today that we can't sort. let me try to make an example of what i was trying to explain.

pnqnpd <--- that is my stack

my function sees that the first thing out of order is the 2nd nickel. it now calls a funtion that flips the pile to now look like:

nqnppd

what it is eventually going to do is get the largest size coin on top and just flip the whole pile.

o well, thanks for the help though.