All pastes #342223 Raw Edit

Someone

public text v1 · immutable
·published 2007-02-06 04:59 UTC
rendered paste body
import java.io.*;
import java.util.*;

/**
 * This program takes in a file with integers and sorts it with heapsort
 */

public class HeapSort {

        /**
         * main method
         */

        public static void main (String[] args) {

                if( args.length != 1) {
                        System.err.println("Usage: java HeapSort filename");
                        System.exit(0);
                } else {

                        Scanner input=null;
                        int[] items;
                        ArrayList list = new ArrayList();

                        try {

                                input = new Scanner(new File(args[0]));                
                        } catch(FileNotFoundException fnf) {
                                System.err.println(fnf);
                        }

                        while(input.hasNext()) {
                                list.add(input.nextInt());                             
                        }

                        input.close();

                        items = new int[list.size()];
                        list.toArray(items);

                }
        }

} //HeapSort