bool CheckSuits(HandIs& eval, SortedType hand) { bool found = false; bool isStraight = IsStraight(hand); bool sameSuits = SameSuits(hand); hand.ResetList(); int first = hand.GetNextItem().GetRank(); if (sameSuits) { found = true; if (isStraight) { if (first == 10) eval = ROYAL; else eval = STRAIGHT_FLUSH; } else eval = FLUSH; } else if (isStraight) { eval = STRAIGHT; found = true; } return found; }
bool SameSuits(SortedType hand) { hand.ResetList(); bool stillPossible = true; int limit = hand.GetLength(); Card card1 = hand.GetNextItem(); Card card2 = hand.GetNextItem(); int comparisons = 1; while (stillPossible) { if (card1.GetSuit() == card2.GetSuit()) { if (comparisons < limit) { card1 = card2; card2 = hand.GetNextItem(); comparisons++; } else stillPossible = false; } else stillPossible = false; } if (comparisons == limit) return true; else return false; }
void BuildCounter(SortedType hand) { for (int index = 0; index <= 14; index++) counter[index] = 0; hand.ResetList(); int limit = hand.GetLength(); for (int index = 1; index <= limit; index++) { int increment = hand.GetNextItem().GetRank(); counter[increment] = counter[increment]+ 1; } }
int main() { ItemType item[MAX_ITEM]; SortedType list; item[0].Initialize(67); item[1].Initialize(89); item[2].Initialize(100); item[3].Initialize(12); item[4].Initialize(32); for(int i = 0; i < MAX_ITEM; i++) { list.InsertItem(item[i]); } list.IsFull() ? cout << "List is not empty" : cout << "list is empty"; cout << endl; cout << "Length of the list is : " << list.LengthIs() << endl; cout << "Contents of the list : "; FOR() { ItemType printItem; list.GetNextElement(printItem); printItem.Print(); } cout << endl; cout << endl; int key; ItemType deleteKey; cout << "Enter what you want to delete : "; cin >> key; deleteKey.Initialize(key); list.DeleteItem(deleteKey); cout << "After deletion the length of the list : " << list.LengthIs() << endl; cout << "Contents of the list after deletion : "; list.ResetList(); for(int i = 0; i < list.LengthIs(); i++) { ItemType printItem; list.GetNextElement(printItem); printItem.Print(); } cout << endl; cout << "Emptying the list........." << endl; list.MakeEmpty(); list.IsFull() ? cout << "List is not empty" : cout << "list is empty"; cout << endl; cout << "Resetting the list.............." << endl; list.ResetList(); return 0; }
void SortedType::MergeLists(SortedType &list1, SortedType &list2) { list1.ResetList(); list2.ResetList(); this->MakeEmpty(); ItemType list1Item; ItemType list2Item; NodeType* newNode; int list1Counter = 0; int list1Length = list1.GetLength(); int loopLength = list1.GetLength() + list2.GetLength(); list1Item = list1.GetNextItem(); list2Item = list2.GetNextItem(); for(int count = 0; count < loopLength; count++) { newNode = new NodeType; newNode->next = NULL; //std::cout << "We are at " << count << std::endl; if((list1Item.ComparedTo(list2Item) == LESS) && list1Counter < list1Length ) { //std::cout << "We are at item 1 less" << std::endl; if(listData == NULL) { newNode->info = list1Item; listData = newNode; } else { newNode->info = list1Item; currentPos->next = newNode; } list1Item = list1.GetNextItem(); list1Counter++; } else { //std::cout << "We are at item 2 less" << std::endl; if(listData == NULL) { newNode->info = list2Item; listData = newNode; } else { //std::cout << "We are in else" << std::endl; newNode->info = list2Item; currentPos->next = newNode; } list2Item = list2.GetNextItem(); } //std::cout << "We are outside if statements" << std::endl; if(count == 0) { currentPos = newNode; } else { currentPos->next = newNode; currentPos = currentPos->next; } length++; //std::cout << "We are at end of the loop" << std::endl; } }