Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. package project6.examples;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6.  
  7. import project6.classes.ArrayHeap;
  8. import project6.classes.AscendingStringComparator;
  9. import project6.interfaces.Comparator;
  10. import project6.interfaces.Heap;
  11.  
  12. public class SortList {
  13.     public static void main(String[] args) throws FileNotFoundException {
  14.  
  15.         Comparator<String> comparator = new AscendingStringComparator();
  16.         Heap<String> heap = new ArrayHeap<String>(comparator);
  17.         String file = "src/employees.csv";
  18.         String[][] unsortedList = new String[250000][4];
  19.         int counter = 0;
  20.  
  21.         Scanner scanner = new Scanner(new File(file));
  22.         while (scanner.hasNext()) {
  23.             // read the next line
  24.             String line = scanner.next();
  25.             // split the line into an array
  26.             String[] split = line.split(",");
  27.             // put the array in 2d array
  28.             for (int i = 0; i < 4; i++) {
  29.                 unsortedList[counter][i] = split[i];
  30.             }
  31.             counter++;
  32.             heap.insertElement(split[2]);
  33.             System.out.println(counter);
  34.         }
  35.         scanner.close();
  36.         int size = heap.size();
  37.         for (int i = 0; i < size; i++) {
  38.             for (int j = 0; j < unsortedList.length; j++) {
  39.                 if (unsortedList[j][2] == heap.minElement()) {
  40.                     for (int k = 0; k < 4; k++) {
  41.                         System.out.print(unsortedList[j][k] + ", ");
  42.                         unsortedList[j][k] = null;
  43.                     }
  44.                     System.out.println();
  45.                 }
  46.             }
  47.             heap.removeMin();
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement