Sort.java |
| /* Sorting class for Exercise 7 7/4/01 James Little */ package jlittle_ex7; import java.util.*; public class Sort{ private Word [] v; private Word w; private int count; private int totalwords; public Sort(Word [] v,int count, int totalwords){ this.v=v; this.count=count; this.totalwords=totalwords; } public void quicksort(int lo, int hi){ if( hi > lo ){ int left=lo, right=hi; int median=v[lo].getWord(); while(right >= left) { while(v[left].getWord() < median) left++; while(v[right].getWord() > median) right--; if(left > right) break; Word temp=v[left]; v[left]=v[right]; v[right]=temp; //swap left++; right--; } quicksort( lo, right);// sort the small elements divide and conquer quicksort( left, hi); } }//quicksort public void writeData(){ for(int z=0; z<count; z++){ int word=v[z].getWord(); if(word==13||word==32||word==10||word==9||word==11) // whitespace values retun a string System.out.println(v[z].getString()+"\t"+Math.round(v[z].getCount()*100.0/totalwords)); else System.out.println(v[z].getChar()+"\t"+Math.round(v[z].getCount()*100.0/totalwords)); } } }//sort |
James Little |