int compares (Card cl, Card c2) This method takes two card objects and returns -1, 0, or 1 if c1 is smaller, equal to, or greater than c2, respectively. You need to compare their suits first and if they have the same suit, then compare their ranks. void quickSort (Card [] cardArray, int first, int last) This method takes a card array as well as two indices. It sorts the cards in the range specified by first and last with quick sort. It first calls the split method to partition the elements in the range into two subarrays, and sorts both subarrays recursively. It repeats this process until the entire array is sorted. int split (Card [] cardArray, int first, int last) This is a helper method for quick sort which takes a card array and two indices. It begins by selecting the first element in the card array as the pivot, and then moves elements so that everything in the left subarray is smaller than the pivot and everything on the right is greater than the pivot. The method returns the final index of the pivot. You will need to call the compares method to make comparisons between cards.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I need help implementing those functions.

public class DeckCards
{
// card comparison
public int compares(Card c1, Card c2)
{
return - 1; // replace this statement with your own return
}

// This is the wrapper method for quick sort
// Do not make any changes to this method!
public void quickSort(Card[] cardArray)
{
quickSortRec(cardArray, 0, cardArray.length - 1);
}

// This is the recursive helper method for quickSort
public void quickSortRec(Card[] cardArray, int first, int last)
{
// TODO: implement this method
}

// This method splits a Card array into two sections, with all the elements less
// than the pivot in the left section and all the elements greater than the pivot
// in the right section
public int split(Card[] cardArray, int first, int last)
{
// TODO: implement this method

return -1;  // replace this statement with your own return
}

// This method takes an int array which represents a complete binary tree as
// the parameter. It checks if the tree stored in the array is a heap.
public boolean isHeap(int[] A)
{
// TODO: implement this method


return false; // replace this statement with your own return
}
}

int compares (Card c1, Card c2)
This method takes two card objects and returns -1, 0, or 1 if c1 is smaller, equal to, or greater
than c2, respectively. You need to compare their suits first and if they have the same suit, then
compare their ranks.
void quickSort (Card [] cardArray, int first, int last)
This method takes a card array as well as two indices. It sorts the cards in the range specified
by first and last with quick sort. It first calls the split method to partition the elements in
the range into two subarrays, and sorts both subarrays recursively. It repeats this process until
the entire array is sorted.
int split (Card [] cardArray, int first, int last)
This is a helper method for quick sort which takes a card array and two indices. It begins by
selecting the first element in the card array as the pivot, and then moves elements so that
everything in the left subarray is smaller than the pivot and everything on the right is greater
than the pivot. The method returns the final index of the pivot. You will need to call the
compares method to make comparisons between cards.
boolean isHeap (int[] A)
This method takes an int array as the parameter and verifies if the elements saved in this
array form a heap. You can assume that the array represents a complete binary tree so the
shape property is already satisfied. You will need to verify that the elements meet the order
property requirement for heaps. Return true if this is a heap, false otherwise. This method is
separate from the above methods and has nothing to do with the card or Deck classes used by
other methods.
Note that you are only supposed to touch the above methods. You are NOT allowed to
create any other methods, instance variables, or make any changes to methods other
than these methods or files other than "Homework6.java". Points will be taken off if you
fail to follow this rule.
Transcribed Image Text:int compares (Card c1, Card c2) This method takes two card objects and returns -1, 0, or 1 if c1 is smaller, equal to, or greater than c2, respectively. You need to compare their suits first and if they have the same suit, then compare their ranks. void quickSort (Card [] cardArray, int first, int last) This method takes a card array as well as two indices. It sorts the cards in the range specified by first and last with quick sort. It first calls the split method to partition the elements in the range into two subarrays, and sorts both subarrays recursively. It repeats this process until the entire array is sorted. int split (Card [] cardArray, int first, int last) This is a helper method for quick sort which takes a card array and two indices. It begins by selecting the first element in the card array as the pivot, and then moves elements so that everything in the left subarray is smaller than the pivot and everything on the right is greater than the pivot. The method returns the final index of the pivot. You will need to call the compares method to make comparisons between cards. boolean isHeap (int[] A) This method takes an int array as the parameter and verifies if the elements saved in this array form a heap. You can assume that the array represents a complete binary tree so the shape property is already satisfied. You will need to verify that the elements meet the order property requirement for heaps. Return true if this is a heap, false otherwise. This method is separate from the above methods and has nothing to do with the card or Deck classes used by other methods. Note that you are only supposed to touch the above methods. You are NOT allowed to create any other methods, instance variables, or make any changes to methods other than these methods or files other than "Homework6.java". Points will be taken off if you fail to follow this rule.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Unfortunately, the code itself executes but recursively in infinite loop. Is there a reason why it is doing that?

Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY