Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting.

Similar presentations


Presentation on theme: "CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting."— Presentation transcript:

1 CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting

2 CS 410 Applied Algorithms 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.

3 CS 410 Applied Algorithms 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.

4 CS 410 Applied Algorithms 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; }

5 CS 410 Applied Algorithms 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; }

6 CS 410 Applied Algorithms 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; }

7 CS 410 Applied Algorithms 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;

8 CS 410 Applied Algorithms

9 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

10 CS 410 Applied Algorithms 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.


Download ppt "CS 410 Applied Algorithms Applied Algorithms Lecture #5 Sorting."

Similar presentations


Ads by Google