Question

Using C programming How to rank this array list {'6S', '5H', 'TS', '2D'} like {'2D', '5H',...

Using C programming
How to rank this array list {'6S', '5H', 'TS', '2D'} like {'2D', '5H', '6S', 'TS'}?

the rank is followed by this list {'2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'}?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

In such cases, you would have to maintain different array for suit and face. And, each element in the array would have two data: face and value given as:

char *suits[4] = {"H","D","C","S"};

char *values[13]= {"2","3","4","5","6","7", "8","9","T","J","Q","K", "A"};

Now, to compare two cards, we would need:

int compareface(const void * c1, const void * c2)

{

const int cd1 = *(const int*)c1;

const int cd2 = *(const int*)c2;

if(cd1 % 13 > cd2 % 13) return 1;

if(cd1 % 13 == cd2 % 13) return 0;

return -1;

}

int comparesuit(const void * c1, const void * c2)

{

const int cd1 = *(const int*)c1;

const int cd2 = *(const int*)c2;

if(cd1 / 13 > cd2 / 13) return 1;

if(cd1 / 13 == cd2 / 13) return 0;

return -1;

}

Finally, to sort the cards, we can do something like:

// sort the cards by card suit:

qsort(arr, 4, sizeof(int), comparesuit);

// sort the cards by card value:

qsort(arr, 4, sizeof(int), compareface);

Add a comment
Know the answer?
Add Answer to:
Using C programming How to rank this array list {'6S', '5H', 'TS', '2D'} like {'2D', '5H',...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • In an 2D array I have the following data stored. Now I have to do code...

    In an 2D array I have the following data stored. Now I have to do code in C language to do the following: If distance between 1 &4 and 5&8 in any line is greater than 2 , then delete that row. And then update the 2D array. If there is no pair of 1 &4 or 5&8 in any row skip that row. Please help to do the code in C. 0 1 2 3 4 9 0 1...

  • Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating...

    Programming Language: C++ Develop a seat reservation system for your airline. Consider the following airline seating pattern: A         1          2          3          4          5          6          7          8          9          ……    100 B         1          2          3          4          5          6          7          8          9          ……    100 AISLE C         1          2          3          4          5          6          7          8          9          ……    100 D         1          2          3          4          5          6          7          8          9          ……    100 Either use 2D STL array (array that contains array) or 4 single dimensional STL arrays of size 100. Write a program to display a menu to the user with the options to reserve a seat of choice, reserve a window seat, reserve an aile seat, reserve a seat (any available), withdraw reservation, update reservation (change seat) and display...

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

  • How do you do reverse arrayList? using recursion? displaying it for example Normal array list 1...

    How do you do reverse arrayList? using recursion? displaying it for example Normal array list 1 2 3 4 5 6 7 reverse array list 7 6 5 4 3 2 1

  • 3. [25 points] Here's another example of using dynamic programming over intervals (like we saw with...

    3. [25 points] Here's another example of using dynamic programming over intervals (like we saw with the RNA Secondary Structure problem) You're given an arithmetic expression consisting of positive integers separated by +s and s but without parentheses, and the goal is to determine the maximum possible value the expression could have by inserting parentheses in some way. For example, with 9-1+9-1 the max value is (9-1)(9-1) 16 (by the way, ((9-1)+9)-1 is an alternative parenthesization that achieves this value),...

  • The answer need to write in C programming. QUESTION 2 Write a program using array to...

    The answer need to write in C programming. QUESTION 2 Write a program using array to generate a multiplication table based on the user's input. For example if user enter 5 as input then a multiply table for 1 to 5 is printed as output as shown in Figure Q2. There are three main steps in this program which are: Print rows (a) (b) Print columns Print multiplication of data inside table (c) Select C:\example1 \bin\Debuglexample 1.exe enter the value...

  • C++ program Write a program which: 1. Enters data into the 2D array of integers which...

    C++ program Write a program which: 1. Enters data into the 2D array of integers which is 5x5 The data should be entered with an assignment statement using nested for loops that is do not scan in the data. The data should be: 1 2 4 8 16 1 3 9 27 81 1 4 16 64 256 1 5 25 125 625 1 6 36 216 1296 2. Print out the following using a nested for loop Row 0:...

  • C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playi...

    C Program Please! Thanks! Spring 2019 ECE 103 Engineering Programming Problem Statement A standard deck of playing cards contains 52 cards. There are four suits (heart, diamond club +, spade+) and thirteen ranks (ace, 2 thru 10,jack, queen, king) per suit. Rank Numeric Value 10 10 10 10 gueen 10 Write a program that does the following: I. Simulates a randomized shuffling of a 52 card deck 2. Determines how many combinations of 21 exist in the deck by following...

  • PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE...

    PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE PLEASE USE C AS A PROGRAMMING LANGUAGE 11. Initialize a integers in the two-dimensional array testArray to the values 1 through 9 using 1 or more while loops so that the array could be visualized as: 1 2 3 LA 5 6 7 8 9...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT