Computer Science Canada Bubble Sort with a 2D array ?? |
Author: | implosion [ Wed May 21, 2008 9:34 pm ] | ||
Post subject: | Bubble Sort with a 2D array ?? | ||
I have a assignment that involves me outputting a deck in order, shuffling it and then using multiple sorts to sort them back. i'm using blue j. i keep getting an error on this line if (Deck[cardnum][cardnum].compareTo(Suit[cardnum+1])>0); it says it finds the array but cant find the integer ?
|
Author: | HeavenAgain [ Wed May 21, 2008 9:45 pm ] |
Post subject: | RE:Bubble Sort with a 2D array ?? |
look closer at your code what is Suit[], or what is Suit, for(int Suit = 0 ; Suit <= 3 ; Suit ++) |
Author: | implosion [ Thu May 22, 2008 7:53 pm ] | ||
Post subject: | Re: Bubble Sort with a 2D array ?? | ||
okay never mind. i had a ton of troubles with the 2D array... i changed my code to this i'm not sure on how to do the rest of the sorts. is there a way to do the merge sort with a String array ? everywhere i've checked they used a int array.
|
Author: | syntax_error [ Thu May 22, 2008 7:59 pm ] |
Post subject: | RE:Bubble Sort with a 2D array ?? |
I maybe wrong but simple have the cards in descending order along with the correct subsequent indices, and simple treat the indices like ints and play around wit them as such that should take out the string problem, if you only deal with the indices. |
Author: | Aziz [ Fri May 23, 2008 11:41 am ] |
Post subject: | RE:Bubble Sort with a 2D array ?? |
> and < operators only work for numerical values. You'll have to use the .compareTo() method of String. Read this: http://www.javabeginner.com/java-string-comparison.htm |
Author: | shadowman544 [ Sat May 24, 2008 8:26 pm ] |
Post subject: | Re: Bubble Sort with a 2D array ?? |
i believe a way to make this a little more in depth would be to make an object called "card" with for say the variables to hold suit and value(a,2-10 and j,q,k). you should then perhaps make another obect called "deck" and give it the contents of a deck of cards (52cards a-k) and the required methods to act as a deck (ex. shuffle and deal) and an object that is a "player" and an object called "hand"(play,pickup). This may eliminate your need for a 2d array. |