Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The attached template deals a deck of 5 2 cards in random order into an array named udeck [ 5 2 ] ( for unsorted

The attached template deals a deck of 52 cards in random order into an array named udeck[52](for unsorted deck). The cards are each stored in a structure which has been typedef'ed and given the type name "card". Use the Rank Sort algorithm discussed this week to sort the cards in order. The cards are in four suits, Clubs ('C'), Diamonds ('D'), Hearts ('H'), Spades ('S'), and the suits are ordered 'C'<'D'<'H'<'S'(i.e. all Clubs are less than all Diamonds, and so forth). The card ranks are '2' through '9', ten ('T'), Jack ('J'), Queen ('Q'), King ('K'), and Ace ('A'), and are ordered from low '2' to high 'A', respectively. As examples, 'AC'<'2D', and 'TS'<'JS'. Update the template to sort the cards in order with the Parallel Rank Sort algorithm using 52 processors. Assigned the ordered cards to the sorted deck sdeck[52]. Display the sorted deck using the same function that displays the unsorted deck. Post your solution to this assignment as "assign2.c". The output should look something like this:
TS 5S KH 8H 3H JD 6D AC 9C 4C QS 7S 2S
TH 5H KD 8D 3D JC 6C AS 9S 4S QH 7H 2H
TD 5D KC 8C 3C JS 6S AH 9H 4H QD 7D 2D
TC 5C KS 8S 3S JH 6H AD 9D 4D QC 7C 2C
2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AC
2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD AD
2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AH
2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AS
SEQUENTIAL EXECUTION TIME: 747943
PARALLEL EXECUTION TIME: 25681
SPEEDUP: 29.12
NUMBER OF PROCESSORS USED: 53/* Assignment 2*/
/* Name: ______*/
#define DECK 52
#define SUIT_SZ 4
#define RANK_SZ 13
#define APRIME 47
typedef struct
{
char suit;
char rank;
} card;
char suits[SUIT_SZ]={'C','D','H','S'};
char ranks[RANK_SZ]={'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
card udeck[DECK], sdeck[DECK];
int compare_cards(card a, card b)
{
return 0;
}
void putinPlace(int src)
{
card testval;
testval = udeck[src];
}
void deal()
{
int i, m, v, r;
m = APRIME;
v = m;
for (i =0; i < DECK; i++)
{
r = v % DECK;
udeck[i].suit = suits[r / RANK_SZ];
udeck[i].rank = ranks[r % RANK_SZ];
v += m;
}
}
void display(card dk[DECK])
{
int i;
for (i =0; i < DECK; i++)
{
cout <<""<< dk[i].rank << dk[i].suit;
if (i % RANK_SZ ==(RANK_SZ -1))
cout << endl;
}
}
int main()
{
int i;
cout << endl;
deal();
display(udeck);
/*
Parallel Rank Sort
*/
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago