| | |
Tricky Sorting Algorthm Help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Solved Threads: 0
A friend of mine wanted to see if I could figure this out.. and it's driving me crazy!! Maybe I'm just over thinking it? Anyways, can anyone figure this out?
Design an algorithm to sort a deck of cards with the restriction that the cards must be kept stacked in the deck, and the only allowed operations are to look at the value of the top two cards, to exchange the top two cards, and to move the top card to the bottom of the deck
Design an algorithm to sort a deck of cards with the restriction that the cards must be kept stacked in the deck, and the only allowed operations are to look at the value of the top two cards, to exchange the top two cards, and to move the top card to the bottom of the deck
•
•
Join Date: Sep 2007
Posts: 12
Reputation:
Solved Threads: 0
Well, what I have so far is something like bubble sort. Apparently I'm missing something since it doesn't produce correct results.
a) Assume cards have values 0-51
b) If card A is less than card B do nothing, else swap.
c) Put card A on the bottom of the deck, repeat 52 times (51?).
For example
1 2 3 4 4 4 4 ... Which means it will continue looping in the incorrect
2 3 4 1 2 3 1 sequence and therefore never sort.
3 4 1 2 3 1 2
4 1 2 3 1 2 3
a) Assume cards have values 0-51
b) If card A is less than card B do nothing, else swap.
c) Put card A on the bottom of the deck, repeat 52 times (51?).
For example
1 2 3 4 4 4 4 ... Which means it will continue looping in the incorrect
2 3 4 1 2 3 1 sequence and therefore never sort.
3 4 1 2 3 1 2
4 1 2 3 1 2 3
Last edited by chris53825; Nov 12th, 2007 at 3:10 pm.
Stop trying to write code before you've fully understood the process for one thing.
Shuffle a suit, then look at the cards to see what order they're in.
Then implement your "algorithm" until you've moved 13 cards, then look at them again to see how the situation has changed.
- are they fully sorted
- are they still unsorted, but it's looking a bit better
- is it the same as it was before.
Shuffle a suit, then look at the cards to see what order they're in.
Then implement your "algorithm" until you've moved 13 cards, then look at them again to see how the situation has changed.
- are they fully sorted
- are they still unsorted, but it's looking a bit better
- is it the same as it was before.
![]() |
Similar Threads
- Math.max prob???...XD (Java)
- sorting stl::map (C++)
- counting comparisons when sorting (C++)
- sorting an array of string (C)
- help by sorting a simply linked list (C)
- sorting file (C)
- sorting 2d arrays (C)
- re: Sorting Algorithms (C++)
Other Threads in the C++ Forum
- Previous Thread: convert integer to array of character???
- Next Thread: I Need Help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node output parameter pointer problem program programming project proxy python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






