Question
package csci3230.hw4; import java.io.File; import java.io.IOException; import java.util.Iterator; import java.util.LinkedList; import java.util.Random; public class PQList extends LinkedList { private static final long serialVersionUID = 1L;
package csci3230.hw4;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Random;
public class PQList extends LinkedList
private static final long serialVersionUID = 1L;
LinkedList
public void insert(Integer key){
// your code goes here
}
public Integer removeMin() {
if(!list.isEmpty()){
return list.removeFirst();
}else{
return null;
}
// your code goes here
}
public String toString() {
StringBuilder s = new StringBuilder();
for (Integer item : list)
s.append(item + " ");
return s.toString();
}
public static void main(String[] args) throws IOException {
int n, seed;
File outputFile;
File dir = new File(".");
if (args.length > 0) {
n = Integer.parseInt(args[0]);
seed = Integer.parseInt(args[1]);
}else {
n = 10;
seed = 3;
}
if (args.length == 3) {
outputFile = new File(args[2]);
} else {
outputFile = new File(dir.getCanonicalPath() + File.separator + "Files/testOut_PQ");
}
OutputWriter out = new OutputWriter(outputFile);
Random r = new Random(seed);
PQList pq = new PQList();
for (int i = 0; i < n; i++) {
pq.insert(r.nextInt(100));
}
out.writeOutput("Number of Integer items as input: "+ n);
out.writeOutput(pq.toString());
out.writeOutput("");
out.writeOutput("Sorted output using Selection sort:");
for (int i = 0; i < n; i++) {
Integer min = pq.removeMin();
out.writeOutput(min.toString());
}
}
}
Output:
Number of Integer items as input: 10
34 60 10 81 28 2 49 64 59 61
Sorted output using Selection sort:
34
60
10
81
28
2
49
64
59
61
Im having trouble writing my insert() method. Can you help me with with my insert method and can you check my removeMin() method. The methods are suppose to be implemented such that it implements selection sort (ascending)in the main method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started