Tricky Sorting Algorthm Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 12
Reputation: chris53825 is an unknown quantity at this point 
Solved Threads: 0
chris53825 chris53825 is offline Offline
Newbie Poster

Tricky Sorting Algorthm Help

 
0
  #1
Nov 12th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Tricky Sorting Algorthm Help

 
0
  #2
Nov 12th, 2007
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 12
Reputation: chris53825 is an unknown quantity at this point 
Solved Threads: 0
chris53825 chris53825 is offline Offline
Newbie Poster

Re: Tricky Sorting Algorthm Help

 
0
  #3
Nov 12th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Tricky Sorting Algorthm Help

 
0
  #4
Nov 12th, 2007
Perhaps start with a deck of cards (or maybe just one suit for easy handling), and try your algorithm out for real.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 12
Reputation: chris53825 is an unknown quantity at this point 
Solved Threads: 0
chris53825 chris53825 is offline Offline
Newbie Poster

Re: Tricky Sorting Algorthm Help

 
0
  #5
Nov 12th, 2007
Originally Posted by Salem View Post
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...?
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Tricky Sorting Algorthm Help

 
0
  #6
Nov 12th, 2007
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC