## Search ObiokusThoughts (Posts Only)

### The Inherent Rationale Of Perception

Perception is one of the most important factors affecting our day to day lives as human beings.  I believe it is one of the most underrate...

## Donate

Use the button below to make one time or recurring donations to help generate income. Thank you very much for your generosity. Please continue to enjoy ObiokusThoughts.com ### Template for File Processing in Java (some bugs may occur)

/*
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pt_2152_obobotette0;

//import packages
import java.io.*;
import java.util.*;

/**
*
* @author obobotette0
*/
public class PT_2152_obobotette0 {

/**
* @param args the command line arguments
*/

public static void quicksort(int[] point, int low, int high) {
//temp variable for swap
int temp;

//range variables
int l = low;
int h = high;

//create midpoint and middle node
int mid = (low + high) / 2;
int median = point[mid];
while (l <= h) {
while (point[l] < median) {
l++;
}

while (point[h] > median) {
h--;
}

if (l <= h) {
temp = point[l];
point[l] = point[h];
point[h] = temp;
l++;
h--;

}
}
if (low < h) {
quicksort(point, low, h);
}
if (l < high) {
quicksort(point, l, high);
}

}

public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
int test_array[] = new int;
int i = 0;
String pt_filename = new String();
String pt_filename2 = new String();
pt_filename = "H:\\My Documents\\NetBeansProjects\\PT_2152_obobotette0\\src\\pt_2152_obobotette0\\COSC489_PT_2152_Input.txt";
pt_filename2 = "H:\\My Documents\\NetBeansProjects\\PT_2152_obobotette0\\src\\pt_2152_obobotette0\\COSC489_PT_2152_Output_obobotette0.txt";

File pt_input = new File(pt_filename);

//while there is more, read file and increase iterator
i++;

}

//begin output files
FileWriter pt_output = new FileWriter(pt_filename2);
PrintWriter pt_write = new PrintWriter(pt_output);
String format_out = new String();

//output index value during each iteration
for (int x = 0; x <= i; x++) {
format_out = x + ": " + test_array[x] + ",\t\t";
pt_write.append(format_out);

//print after every 5 numbers
if (x > 0 && x % 5 == 0) {
pt_write.flush();
pt_write.append("\n");
}

}
pt_write.append("\n\n");

//print again from the last entry to the first
for (int y = i; y >= 0; y--) {
format_out = y + ": " + test_array[y] + ",\t\t";
pt_write.append(format_out);

//flush after every 5 entries
if (y % 5 == 0) {
pt_write.flush();
pt_write.append("\n");
}
}
pt_write.append("\n\n");

quicksort(test_array, 0, i);
for (int z = 0; z <= i; z++) {
format_out = z + ": " + test_array[z] + ",\t\t";
pt_write.append(format_out);
if (z > 0 && z % 5 == 0) {
pt_write.flush();
pt_write.append("\n");
}

}
//Print last number of file after sorting
//pt_write.append("78:"+test_array+",\n\n");
pt_write.flush();

Random randnum = new Random(20150418);
int[] small = new int;
int[] medium = new int;
int[] large = new int;

//individual loop for each array
for (int o = 0; o < 1000; o++) {

small[o] = randnum.nextInt(100001);
}
for (int o = 0; o < 20000; o++) {
medium[o] = randnum.nextInt(100001);
}

for (int o = 0; o < 50000; o++) {
large[o] = randnum.nextInt(100001);
}

//start and stop variable for each array sort
long small_start;
long small_stop;
long medium_start;
long medium_stop;
long large_start;
long large_stop;

small_start = System.currentTimeMillis();
quicksort(small, 0, small.length - 1);
small_stop = System.currentTimeMillis();

medium_start = System.currentTimeMillis();
quicksort(medium, 0, medium.length - 1);
medium_stop = System.currentTimeMillis();

large_start = System.currentTimeMillis();
quicksort(large, 0, large.length - 1);
large_stop = System.currentTimeMillis();

long small_time = small_stop - small_start;
long medium_time = medium_stop - medium_start;
long large_time = large_stop - large_start;

String small_stat = new String();
String small_content = new String();
String medium_stat = new String();
String medium_content = new String();
String large_stat = new String();
String large_content = new String();

small_stat = "\nSize:" + small.length + ",\t\tTime:" + small_time + ",\t\t\n";
small_content = "\n1st:" + small + ",\t\t100th:" + small + ",\t\t200th:" + small + ",\t\t500th:" + small + "\n\n";

medium_stat = "\nSize:" + medium.length + ",\t\tTime:" + medium_time + ",\t\t\n";
medium_content = "\n1st:" + medium + ",\t\t100th:" + medium + ",\t\t200th:" + medium + ",\t\t500th:" + medium + "\n\n";

large_stat = "\nSize:" + large.length + ",\t\tTime:" + large_time + ",\t\t\n";
large_content = "\n1st:" + large + ",\t\t100th:" + large + ",\t\t200th:" + large + ",\t\t500th:" + large + "\n\n";

pt_write.append(small_stat + small_content);
pt_write.flush();

pt_write.append(medium_stat + medium_content);
pt_write.flush();

pt_write.append(large_stat + large_content);
pt_write.flush();
}

}