Created
January 23, 2020 17:14
-
-
Save raunaqsingh2020/73c2fa2efb9f59599afff9e9e08dff2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class freeResponse2 | |
{ | |
public freeResponse2() | |
{ | |
String[] artists = {"Ariana Grande", "Ariana Grande", "Ariana Grande","Halsey","Halsey","Post Malone","Post Malone","Post Malone","Ariana Grande","Ariana Grande","Ariana Grande","Ariana Grande","Lady Gaga","Lady Gaga","Lady Gaga","Lady Gaga","Jonas Brothers","Jonas Brothers","Jonas Brothers","Jonas Brothers","Jonas Brothers","Jonas Brothers","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Lil Nas X","Billie Eilish","Billie Eilish","Billie Eilish","Billie Eilish","Billie Eilish","Billie Eilish","Shawn Mendes","Lizzo","Lizzo","Lizzo","Lizzo","Lizzo","Lizzo","Travis Scott","Selena Gomez","Selena Gomez","Post Malone","Post Malone","Post Malone","Post Malone","The Weeknd","Mariah Carey","Mariah Carey"}; | |
LinkedList artistsList = new LinkedList(); | |
for(int i = 0; i < artists.length; i++){ | |
artistsList.insert(artistsList, artists[i]); | |
} | |
LinkedList noDuplicates = removeDuplicates(artistsList); | |
noDuplicates.printList(noDuplicates); | |
LinkedList corrNums = new LinkedList(); | |
for(int i = 0; i < noDuplicates.getSize(noDuplicates); i++){ | |
String artist = (String)(noDuplicates.get(noDuplicates, i)); | |
int artistCount = 0; | |
for(int j = 0; j < artists.length; j++){ | |
if(artists[j].equals(artist)) | |
artistCount++; | |
} | |
corrNums.insert(corrNums, artistCount); | |
} | |
System.out.println(); | |
corrNums.printList(corrNums); | |
System.out.println(); | |
LinkedList corrNums2 = new LinkedList(); //duplicate of corrNums | |
LinkedList noDuplicates2 = removeDuplicates(artistsList); | |
for(int i = 0; i < corrNums.getSize(corrNums); i++){ | |
corrNums2.insert(corrNums2, corrNums.get(corrNums, i)); | |
} | |
for(int i = 0; i < 3; i++){ | |
int indexLargest = -1; | |
int largest = 0; | |
for(int j = 0; j < corrNums2.getSize(corrNums2); j++){ | |
if((int)(corrNums2.get(corrNums2,j))>largest){ | |
largest = (int)(corrNums2.get(corrNums2,j)); | |
indexLargest = j; | |
} | |
} | |
System.out.println(noDuplicates2.get(noDuplicates2, indexLargest) + " " + corrNums2.get(corrNums2, indexLargest)); | |
if(indexLargest!=0){ | |
corrNums2.remove(corrNums2,indexLargest); | |
noDuplicates2.remove(noDuplicates2,indexLargest); | |
}else{ | |
corrNums2.deleteFront(corrNums2); | |
noDuplicates2.deleteFront(noDuplicates2); | |
} | |
} | |
} | |
//From Free Response #1 | |
public LinkedList removeDuplicates(LinkedList original){ | |
LinkedList newList = new LinkedList(); | |
for(int i = 0; i < original.getSize(original); i++){ | |
if (newList.find(newList, original.get(original, i))==-1) { | |
newList.insert(newList, original.get(original, i)); | |
} | |
} | |
return newList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment