I was provided with the following code. However, when executing it goes to an infite loop and cannot seem to ppass by that. public int compares(Card c1, Card c2){     // TODO: implement this method     if(c1.getSuit() > c2.getSuit())     return 1;          if(c1.getSuit() < c2.getSuit())     return -1;          else     {                  if(c1.getRank() > c2.getRank())         return 1;                  if (c1.getRank() < c2.getRank())         return -1;                  else         return 0;              } public void quickSortRec(Card[] cardArray, int first, int last) {     if (first < last) {         int splitPoint;          splitPoint = split(cardArray, first, last);                  quickSortRec(cardArray, first, splitPoint);         quickSortRec(cardArray, splitPoint + 1, last);      } } public int split(Card[] cardArray, int first, int last){     Card splitValue = cardArray[first];     while(first <= last) {         while(compares(cardArray[first],splitValue) == -1) {             first++;         }              while(compares(cardArray[last],splitValue) == 1) {             last--;         }              if (first <= last)         {             Card temp = cardArray[first];             cardArray[first] = cardArray[last];             cardArray[last] = temp;             first++;             last--;         }     }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I was provided with the following code. However, when executing it goes to an infite loop and cannot seem to ppass by that.

public int compares(Card c1, Card c2){
    // TODO: implement this method
    if(c1.getSuit() > c2.getSuit())
    return 1;
    
    if(c1.getSuit() < c2.getSuit())
    return -1;
    
    else
    {
        
        if(c1.getRank() > c2.getRank())
        return 1;
        
        if (c1.getRank() < c2.getRank())
        return -1;
        
        else
        return 0;
        
    }

public void quickSortRec(Card[] cardArray, int first, int last) {
    if (first < last) {
        int splitPoint; 
        splitPoint = split(cardArray, first, last);
        
        quickSortRec(cardArray, first, splitPoint);
        quickSortRec(cardArray, splitPoint + 1, last); 
    }
}


public int split(Card[] cardArray, int first, int last){
    Card splitValue = cardArray[first];

    while(first <= last) {
        while(compares(cardArray[first],splitValue) == -1) {
            first++;
        }
    
        while(compares(cardArray[last],splitValue) == 1) {
            last--;
        }
    
        if (first <= last)
        {
            Card temp = cardArray[first];
            cardArray[first] = cardArray[last];
            cardArray[last] = temp;
            first++;
            last--;
        }
    }
    return first - 1;
}

IJ
File Edit View Navigate Code Refactor Build Run Tools VCS Window Help
TestHomework6 ▼
HW6 New
Card.java X Ⓒ Deck.java X Ⓒ Homework6.java X
HW6 New C:\Users\rodri\ld
1
g/…../
.idea
3
>
out
4
public class Homework6
>
src
5
{
Decks.dat
// card comparison
HW6 New.iml
public int compares (Card c1, Card c2)
> III External Libraries
{
Scratches and Consoles
// TODO: implement this method
if
(c1.getSuit() > c2.getSuit())
return 1;
if (c1.getSuit() < c2.getSuit())
return -1;
else
15 Ć
{
if (c1.getRank() > c2.getRank())
TestHomework6 x
.jdks\openjdk-17.0.2\bin\java.exe "-javaagent: C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=54015:C:\Program Fi
>>
Event Log
Build
Version Control ▶. Run
TODO
> Problems > Terminal
Build completed successfully in 2 sec, 847 ms (moments ago)
59:19 CRLF UTF-8 4 spaces
Structure
Bookmarks
Run:
O
IÊ a IP
BEREREB
10
11
12
13
14
16
@
HW6 New - Homework6.java
TestHomework6.java X
O
x
:
A2 ^ V
||
Transcribed Image Text:IJ File Edit View Navigate Code Refactor Build Run Tools VCS Window Help TestHomework6 ▼ HW6 New Card.java X Ⓒ Deck.java X Ⓒ Homework6.java X HW6 New C:\Users\rodri\ld 1 g/…../ .idea 3 > out 4 public class Homework6 > src 5 { Decks.dat // card comparison HW6 New.iml public int compares (Card c1, Card c2) > III External Libraries { Scratches and Consoles // TODO: implement this method if (c1.getSuit() > c2.getSuit()) return 1; if (c1.getSuit() < c2.getSuit()) return -1; else 15 Ć { if (c1.getRank() > c2.getRank()) TestHomework6 x .jdks\openjdk-17.0.2\bin\java.exe "-javaagent: C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.3.1\lib\idea_rt.jar=54015:C:\Program Fi >> Event Log Build Version Control ▶. Run TODO > Problems > Terminal Build completed successfully in 2 sec, 847 ms (moments ago) 59:19 CRLF UTF-8 4 spaces Structure Bookmarks Run: O IÊ a IP BEREREB 10 11 12 13 14 16 @ HW6 New - Homework6.java TestHomework6.java X O x : A2 ^ V ||
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education