Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. import java.util.LinkedList;
  2.  
  3. public class ListSorter{
  4.  
  5. private LinkedList<Integer> list;
  6.  
  7. public ListSorter(LinkedList<Integer> arg){
  8. list=arg;
  9. }
  10.  
  11. public LinkedList<Integer> sort(){
  12. LinkedList<Integer> toReturn;
  13. for(int i=1;i<list.size();i++){
  14. int k=list.get(i);
  15. int j=i-1;
  16. while(i>=0&& list.get(j)>k){
  17. list.set(j+1,list.get(j));
  18. j-=1;
  19. }
  20. list.set(j+1,k);
  21. }
  22. return list;
  23. }
  24.  
  25. }
  26.  
  27.  
  28.  
  29. import java.io.File;
  30. import java.util.Scanner;
  31. import java.util.LinkedList;
  32. import java.io.FileNotFoundException;
  33. import java.util.Collections;
  34. import java.io.PrintWriter;
  35.  
  36. public class boi {
  37.  
  38. public static void main(String[] args) throws FileNotFoundException{
  39. Scanner inScan=new Scanner(new File(args[0]));
  40. LinkedList<Integer> list=new LinkedList<Integer>();
  41. File output=new File(args[1]);
  42. PrintWriter print=new PrintWriter(output);
  43.  
  44. while(inScan.hasNextLine()){
  45. int random=Integer.parseInt(inScan.nextLine());
  46. list.add(random);
  47. }
  48.  
  49. for(int n=1;n<Integer.parseInt(args[2])+1;n++){
  50.  
  51. LinkedList<Integer> temp=new LinkedList<Integer>(list);
  52.  
  53. long start=System.nanoTime();
  54. Collections.sort(temp);
  55. //ListSorter.sort(temp);
  56. long end=(System.nanoTime()-start);
  57.  
  58. print.println(n+","+end);
  59. //System.out.println(n+", "+end);
  60. }
  61. print.close();
  62.  
  63. }
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement