944,167 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1160
  • C++ RSS
Nov 12th, 2007
0

Tricky Sorting Algorthm Help

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chris53825 is offline Offline
12 posts
since Sep 2007
Nov 12th, 2007
0

Re: Tricky Sorting Algorthm Help

Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Nov 12th, 2007
0

Re: Tricky Sorting Algorthm Help

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
Last edited by chris53825; Nov 12th, 2007 at 3:10 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chris53825 is offline Offline
12 posts
since Sep 2007
Nov 12th, 2007
0

Re: Tricky Sorting Algorthm Help

Perhaps start with a deck of cards (or maybe just one suit for easy handling), and try your algorithm out for real.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Nov 12th, 2007
0

Re: Tricky Sorting Algorthm Help

Click to Expand / Collapse  Quote originally posted by Salem ...
Perhaps start with a deck of cards (or maybe just one suit for easy handling), and try your algorithm out for real.
I am actually Lol, the current method I've posted doesn't work and I've tried various other ways. Any ideas...?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chris53825 is offline Offline
12 posts
since Sep 2007
Nov 12th, 2007
0

Re: Tricky Sorting Algorthm Help

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.
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: convert integer to array of character???
Next Thread in C++ Forum Timeline: I Need Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC