Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project6.examples;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.Scanner;
- import project6.classes.ArrayHeap;
- import project6.classes.AscendingStringComparator;
- import project6.interfaces.Comparator;
- import project6.interfaces.Heap;
- public class SortList {
- public static void main(String[] args) throws FileNotFoundException {
- Comparator<String> comparator = new AscendingStringComparator();
- Heap<String> heap = new ArrayHeap<String>(comparator);
- String file = "src/employees.csv";
- String[][] unsortedList = new String[250000][4];
- int counter = 0;
- Scanner scanner = new Scanner(new File(file));
- while (scanner.hasNext()) {
- // read the next line
- String line = scanner.next();
- // split the line into an array
- String[] split = line.split(",");
- // put the array in 2d array
- for (int i = 0; i < 4; i++) {
- unsortedList[counter][i] = split[i];
- }
- counter++;
- heap.insertElement(split[2]);
- System.out.println(counter);
- }
- scanner.close();
- int size = heap.size();
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < unsortedList.length; j++) {
- if (unsortedList[j][2] == heap.minElement()) {
- for (int k = 0; k < 4; k++) {
- System.out.print(unsortedList[j][k] + ", ");
- unsortedList[j][k] = null;
- }
- System.out.println();
- }
- }
- heap.removeMin();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement