Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (s3a):

Could someone please help me with this algorithmic problem?: http://f.imgtmp.com/Faisv.jpg If anything is unclear, ask me and I will try to clarify if I can.

OpenStudy (s3a):

The full question is here actually: http://f.imgtmp.com/TZq27.jpg

OpenStudy (anonymous):

ok. got to think about how you implement this to actually deal the deck first. ie. you take one off the topand then take the next card and put it on the bottom So think about how you do this backwards take a card from the bottom and put it on the top, then add a card on the top My process 1. I created a quick method to "deal the pack" 2. created a method to setup the test data provided 3. tested the "deal" worked correctly 4. created a method to generate the deck (logic as above) 5. checked the created deck dealt out correctly. if you can read java - sample code attached import java.util.LinkedList; import java.util.List; public class Test { private static LinkedList<String> list = new LinkedList<String>(); /** * @param args */ public static void main(String[] args) { shuffle(7); //createTestData(); deal(list); } private static void createTestData() { list.add("1"); list.add("5"); list.add("2"); list.add("4"); list.add("3"); } private static void deal(LinkedList<String> list2) { System.out.println("\nDealing"); while(! list.isEmpty()){ //deal the top card System.out.println(list.removeFirst()); // takes the card at the bottom and adds it to the top of the pack - if the card added was the "1" - deck is finished if (!list.isEmpty()) list.add(list.removeFirst()); } } private static void shuffle(int n) { System.out.println("\\nShuffling"); for (int i = n; i > 0 ; i--) { //adds to the top of the pack list.add(0,""+i); // takes the card at the bottom and adds it to the top of the pack - if the card added was the "1" - deck is finished if (i > 1) list.add(0,list.removeLast()); //Show my working System.out.println(list); } } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!