100 likes | 195 Views
Applied Algorithms. Lecture #5 Sorting. Homework Grading Notes Again. You must turn in your homework in class each Friday. Give me a paper copy in class. Email is not convenient for me. You must turn in the report from the judge. Homework without a Judge report can get a maximum of 85%.
E N D
Applied Algorithms Lecture #5 Sorting
Homework Grading Notes Again • You must turn in your homework in class each Friday. • Give me a paper copy in class. Email is not convenient for me. • You must turn in the report from the judge. • Homework without a Judge report can get a maximum of 85%. • Always turn in a page or two of output. Try and make the input for the output you turn in be non-standard. Test the gotchas! • Include some sort of high level description of the strategy your program uses to solve the problem.
Quiz • We have a 10 minute quiz today on the reading – Chapter 4. • We will continue to have quizzes until the class gets an average score high enough to convince me that people are doing the reading.
Paradigms Character Decoding char *rankChoices = "--23456789TJQKA"; char *suitChoices = "-CDHS"; void trans(Rank rk[6],Suit st[6], int i, char r, char s) { int j; for (j=2; j<=14; j++) if (rankChoices[j]==r) rk[i] = j; for (j=1; j<=4 ; j++) if (suitChoices[j]==s) st[i] = j; }
Comparison typedef int Ordering; #define LT 0 #define GT 1 #define EQ 2 Ordering comp(int i, int j) // Compare two ints { if (i==j) return EQ; if (i<j) return LT; if (i>j) return GT; }
Lexiographic Ordering Ordering lexGraph(int x[], int y[], int low, int high) { int i; // Lexigraphic ordering of x from right-to-left for (i=high; i>=low; i--) { if (x[i] > y[i]) return GT; if (x[i] < y[i]) return LT; } return EQ; }
Data encodes Control enum handTag {HighCard, Pair, TwoPair, ThreeOfaKind, Straight, Flush, FullHouse, FourOfaKind, StraightFlush}; struct Hand { // The union is the info needed to break ties enum handTag tag; // its either One card or a Set of cards union { Rank highCard[6]; // [lowest .. highest] Rank pair[5]; // [lowest .. highest,Pair] Rank twoPair[4]; // [lone card,lower pair,higher pair] Rank threeOfaKind; // Rank of triple Rank straight; // highest card in straight Rank flush[6]; // [lowest .. highest] Rank fullHouse; // Rank of 3-of-a-kind in full house Rank fourOfaKind; // Rank of quad Rank straightFlush; // highest card in straight } data; } xx; typedef struct Hand HAND;
In Class Problems • Vito’s Family 4.6.1 • Page 88 of the text • We will write this together as a class • Bridge 4.6.3 • Page 91 of the text • Keeping in mind today’s lecture. • Pairs of two
Today’s Assignments Read for next time Chapter 5 of the text. pp 102-128 Be prepared to answer questions in class next Friday from the reading. Programming assignment • 4.6.5 Shoemaker's Problem • - Page 94 • Write a solution Submit your solution (until you get it right) Hand in both your program, and the judge output. Those who volunteer to discuss their program get class participation points. Email me solutions before noon on Friday, May 6.