Computer Science > Research Paper > University of Houston - CS 6320ExternalSort.java (All)
import java.util.Scanner; import java.io.PrintWriter; import java.nio.file.Path; import java.nio.file.Paths; public class ExternalSort { public static String sort(String s){ String[] vals = s.sp... lit(" "); int array[] = new int[vals.length]; for(int k = 0; k < vals.length; k++){ array[k] = Integer.parseInt(vals[k]); } for(int j = 1; j < vals.length; j++){ int key = array[j]; int x = j - 1; while(x >= 0 && array[x] > key){ array[x + 1] = array[x]; x = x - 1; } array[x + 1] = key; } String text = ""; for(int k = 0; k < vals.length; k++){ text += array[k] + " "; } return text; } public static void printPath(Path p){ try(Scanner sc = new Scanner(p);){ while(sc.hasNextInt()){ System.out.print(sc.nextInt() + " "); } System.out.println(); } catch(Exception e){ System.out.println(e); } } public static Path extsort(Path t1, int runsize){ Path t2 = Paths.get("C:\\UTD\\DataStrucs\\Project4\\t2.txt"); Path t3 = Paths.get("C:\\UTD\\DataStrucs\\Project4\\t3.txt"); Path t4 = Paths.get("C:\\UTD\\DataStrucs\\Project4\\t4.txt"); try(Scanner sc = new Scanner(t1);){ int total = 0; PrintWriter print1 = new PrintWriter(t3.toString()); PrintWriter print2 = new PrintWriter(t4.toString()); while(sc.hasNextInt()){ int count = 0; String toPrint = ""; while(sc.hasNextInt() && count < runsize){ toPrint += sc.nextInt() + " "; count++; total++; } [Show More]
Last updated: 2 years ago
Preview 1 out of 4 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Apr 10, 2021
Number of pages
4
Written in
This document has been written for:
Uploaded
Apr 10, 2021
Downloads
0
Views
76
In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·