SlideShare a Scribd company logo
1 of 1
Download to read offline
9.18 LAB: Sorting user IDs
Given a main() that reads user IDs (until -1), complete the quicksort() and partition() methods to
sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per
line.
Ex. If the input is:
the output is:
the code to update:
import java.util.Scanner;
import java.util.ArrayList;
public class UserIDSorting {
// TODO: Write the partitioning algorithm - pick the middle element as the
// pivot, compare the values using two index variables l and h (low and high),
// initialized to the left and right sides of the current elements being sorted,
// and determine if a swap is necessary
public static int partition(ArrayList<String> userIDs, int i, int k) {
}
// TODO: Write the quicksort algorithm that recursively sorts the low and
// high partitions
public static void quicksort(ArrayList<String> userIDs, int i, int k) {
}
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
ArrayList<String> userIDList = new ArrayList<String>();
String userID;
userID = scnr.next();
while (!userID.equals("-1")) {
userIDList.add(userID);
userID = scnr.next();
}
// Initial call to quicksort
quicksort(userIDList, 0, userIDList.size() - 1);
for (int i = 0; i < userIDList.size(); ++i) {
System.out.println(userIDList.get(i));
}
}
}

More Related Content

Similar to 918 LAB Sorting user IDs Given a main that reads user ID.pdf

Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
gthe
 
For this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdfFor this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdf
alokindustries1
 
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdfImplement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
info961251
 
Create a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docxCreate a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docx
rajahchelsey
 
Alter your Rectangle class to include compareTo and make any other mod.pdf
Alter your Rectangle class to include compareTo and make any other mod.pdfAlter your Rectangle class to include compareTo and make any other mod.pdf
Alter your Rectangle class to include compareTo and make any other mod.pdf
Stewart9OZBondc
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdfIn JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
feelingspaldi
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 

Similar to 918 LAB Sorting user IDs Given a main that reads user ID.pdf (20)

Procedure to create_the_calculator_application java
Procedure to create_the_calculator_application javaProcedure to create_the_calculator_application java
Procedure to create_the_calculator_application java
 
Data Structure.pdf
Data Structure.pdfData Structure.pdf
Data Structure.pdf
 
Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++Analyzing On-Chip Interconnect with Modern C++
Analyzing On-Chip Interconnect with Modern C++
 
For this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdfFor this lab, you will write the following filesAbstractDataCalc.pdf
For this lab, you will write the following filesAbstractDataCalc.pdf
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Unit IV Notes.docx
Unit IV Notes.docxUnit IV Notes.docx
Unit IV Notes.docx
 
Java execise
Java execiseJava execise
Java execise
 
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdfImplement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
 
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdfUsing Array Approach, Linked List approach, and Delete Byte Approach.pdf
Using Array Approach, Linked List approach, and Delete Byte Approach.pdf
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
Create a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docxCreate a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docx
 
Alter your Rectangle class to include compareTo and make any other mod.pdf
Alter your Rectangle class to include compareTo and make any other mod.pdfAlter your Rectangle class to include compareTo and make any other mod.pdf
Alter your Rectangle class to include compareTo and make any other mod.pdf
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
02.adt
02.adt02.adt
02.adt
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
17515
1751517515
17515
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdfIn JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
In JavaIn a 2D Arraya.)Display the row and column with the hig.pdf
 
Oodp mod4
Oodp mod4Oodp mod4
Oodp mod4
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
 

More from sastaindin

A 2010 Pew Research poll asked 1306 Americans From what yo.pdf
A 2010 Pew Research poll asked 1306 Americans From what yo.pdfA 2010 Pew Research poll asked 1306 Americans From what yo.pdf
A 2010 Pew Research poll asked 1306 Americans From what yo.pdf
sastaindin
 
a 1 The first step is to understand the requirements of th.pdf
a 1 The first step is to understand the requirements of th.pdfa 1 The first step is to understand the requirements of th.pdf
a 1 The first step is to understand the requirements of th.pdf
sastaindin
 
9 Using the key choices complete the crossword puzale by a.pdf
9 Using the key choices complete the crossword puzale by a.pdf9 Using the key choices complete the crossword puzale by a.pdf
9 Using the key choices complete the crossword puzale by a.pdf
sastaindin
 
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
sastaindin
 
9 You are studying the molecular behavior of myosin II S1 .pdf
9 You are studying the molecular behavior of myosin II S1 .pdf9 You are studying the molecular behavior of myosin II S1 .pdf
9 You are studying the molecular behavior of myosin II S1 .pdf
sastaindin
 

More from sastaindin (20)

A 7 year 15000 bond paying a coupon rate of 475 compound.pdf
A 7 year 15000 bond paying a coupon rate of 475 compound.pdfA 7 year 15000 bond paying a coupon rate of 475 compound.pdf
A 7 year 15000 bond paying a coupon rate of 475 compound.pdf
 
A 25 yearold graduate student enters the student health ce.pdf
A 25 yearold graduate student enters the student health ce.pdfA 25 yearold graduate student enters the student health ce.pdf
A 25 yearold graduate student enters the student health ce.pdf
 
a 2 pts Construct the final Fibonacci heap after the fol.pdf
a 2 pts Construct the final Fibonacci heap after the fol.pdfa 2 pts Construct the final Fibonacci heap after the fol.pdf
a 2 pts Construct the final Fibonacci heap after the fol.pdf
 
A 2010 Pew Research poll asked 1306 Americans From what yo.pdf
A 2010 Pew Research poll asked 1306 Americans From what yo.pdfA 2010 Pew Research poll asked 1306 Americans From what yo.pdf
A 2010 Pew Research poll asked 1306 Americans From what yo.pdf
 
a 1 The first step is to understand the requirements of th.pdf
a 1 The first step is to understand the requirements of th.pdfa 1 The first step is to understand the requirements of th.pdf
a 1 The first step is to understand the requirements of th.pdf
 
A 10 year old develops severe pharyngitis at summer camp He.pdf
A 10 year old develops severe pharyngitis at summer camp He.pdfA 10 year old develops severe pharyngitis at summer camp He.pdf
A 10 year old develops severe pharyngitis at summer camp He.pdf
 
A modeling study of the stomatogastric ganglion STG of th.pdf
A  modeling study of the stomatogastric ganglion STG of th.pdfA  modeling study of the stomatogastric ganglion STG of th.pdf
A modeling study of the stomatogastric ganglion STG of th.pdf
 
9 Using the key choices complete the crossword puzale by a.pdf
9 Using the key choices complete the crossword puzale by a.pdf9 Using the key choices complete the crossword puzale by a.pdf
9 Using the key choices complete the crossword puzale by a.pdf
 
9 Sickle Cell Anemia is a condition that shows codominance.pdf
9 Sickle Cell Anemia is a condition that shows codominance.pdf9 Sickle Cell Anemia is a condition that shows codominance.pdf
9 Sickle Cell Anemia is a condition that shows codominance.pdf
 
A Blastula aamas B zigot aamas C Morula aamas D.pdf
A  Blastula aamas   B  zigot aamas   C  Morula aamas   D.pdfA  Blastula aamas   B  zigot aamas   C  Morula aamas   D.pdf
A Blastula aamas B zigot aamas C Morula aamas D.pdf
 
97 Using the table for the t distributions make an assess.pdf
97 Using the table for the t distributions make an assess.pdf97 Using the table for the t distributions make an assess.pdf
97 Using the table for the t distributions make an assess.pdf
 
925 Match the following generally accepted accounting princ.pdf
925 Match the following generally accepted accounting princ.pdf925 Match the following generally accepted accounting princ.pdf
925 Match the following generally accepted accounting princ.pdf
 
8En Alemania los trabajadores Seleccione uno a pued.pdf
8En Alemania los trabajadores    Seleccione uno  a pued.pdf8En Alemania los trabajadores    Seleccione uno  a pued.pdf
8En Alemania los trabajadores Seleccione uno a pued.pdf
 
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
9Tara asiste a una escuela secundaria en un rea urbana Q.pdf
 
900 ABDli yetikinden oluan bir rneklemde 206s nllerin .pdf
900 ABDli yetikinden oluan bir rneklemde 206s nllerin .pdf900 ABDli yetikinden oluan bir rneklemde 206s nllerin .pdf
900 ABDli yetikinden oluan bir rneklemde 206s nllerin .pdf
 
9 You are studying the molecular behavior of myosin II S1 .pdf
9 You are studying the molecular behavior of myosin II S1 .pdf9 You are studying the molecular behavior of myosin II S1 .pdf
9 You are studying the molecular behavior of myosin II S1 .pdf
 
9 What will be the outgut of the C program Aincluderstdich.pdf
9 What will be the outgut of the C program Aincluderstdich.pdf9 What will be the outgut of the C program Aincluderstdich.pdf
9 What will be the outgut of the C program Aincluderstdich.pdf
 
9 Which Git command should be used to update a local reposi.pdf
9 Which Git command should be used to update a local reposi.pdf9 Which Git command should be used to update a local reposi.pdf
9 Which Git command should be used to update a local reposi.pdf
 
9 Private solutions to correct for externalities Consider t.pdf
9 Private solutions to correct for externalities Consider t.pdf9 Private solutions to correct for externalities Consider t.pdf
9 Private solutions to correct for externalities Consider t.pdf
 
9 Size laboratuvarda in vitro biyomalzemelerle cilt dokus.pdf
9 Size laboratuvarda in vitro biyomalzemelerle cilt dokus.pdf9 Size laboratuvarda in vitro biyomalzemelerle cilt dokus.pdf
9 Size laboratuvarda in vitro biyomalzemelerle cilt dokus.pdf
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Krashi Coaching
 

Recently uploaded (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

918 LAB Sorting user IDs Given a main that reads user ID.pdf

  • 1. 9.18 LAB: Sorting user IDs Given a main() that reads user IDs (until -1), complete the quicksort() and partition() methods to sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per line. Ex. If the input is: the output is: the code to update: import java.util.Scanner; import java.util.ArrayList; public class UserIDSorting { // TODO: Write the partitioning algorithm - pick the middle element as the // pivot, compare the values using two index variables l and h (low and high), // initialized to the left and right sides of the current elements being sorted, // and determine if a swap is necessary public static int partition(ArrayList<String> userIDs, int i, int k) { } // TODO: Write the quicksort algorithm that recursively sorts the low and // high partitions public static void quicksort(ArrayList<String> userIDs, int i, int k) { } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); ArrayList<String> userIDList = new ArrayList<String>(); String userID; userID = scnr.next(); while (!userID.equals("-1")) { userIDList.add(userID); userID = scnr.next(); } // Initial call to quicksort quicksort(userIDList, 0, userIDList.size() - 1); for (int i = 0; i < userIDList.size(); ++i) { System.out.println(userIDList.get(i)); } } }