Operating system scan algorithm and SSTF algorithm

Source: Internet
Author: User

Scan

 PackageFour ;Importjava.util.Arrays;ImportJava.util.Scanner; Public classScan { Public voidClockwise (Array Longth,intBeginintTempinto) {        int[]a =New int[Longth.lo.length];  for(inti=0;i<longth.lo.length;i++) A[i]=longth.lo[i]-begin; intb[]=New int[Longth.lo.length];  for(inti=0;i<a.length;i++) B[i]=A[i];                    Arrays.sort (a);  for(intj=0;j<longth.lo.length;j++)                if(a[longth.lo.length-temp+o]==b[j]&&longth.use[j]==false) {System.out.println (longth.lo[j]); LONGTH.USE[J]=true; }            }     Public voidAnticlockwise (Array longth,intBeginintTempinto) {int[]a =New int[Longth.lo.length];  for(inti=0;i<longth.lo.length;i++) A[i]=longth.lo[i]-begin; intb[]=New int[Longth.lo.length];  for(inti=0;i<a.length;i++) B[i]=A[i];                    Arrays.sort (a);  for(intj=0;j<longth.lo.length;j++)                if(a[longth.lo.length-temp-o]==b[j]&&longth.use[j]==false) {System.out.println (longth.lo[j]); LONGTH.USE[J]=true; }        }     Public Static voidMain (string[] args) {intstart; System.out.println ("Input read-write header"); Scanner in=NewScanner (system.in); Start=In.nextint (); System.out.println ("Input sequence Length"); intamount; Amount=In.nextint (); System.out.println ("The input is clockwise or counterclockwise 1 means shun, 2 for inverse"); intTe=In.nextint (); Array a=NewArray (); System.out.println ("Input Sequence"); int[]lon=New int[amount]; Boolean[]using=New Boolean[amount];  for(inti=0;i<amount;i++) {Lon[i]=In.nextint (); Using[i]=false;        } A.seta (Lon);        A.setuse (using); Scan b=NewScan (); intTemp=0;  for(inti=0;i<amount;i++)            if(a.lo[i]>=start) Temp++; if(te==1){             for(inti=0;i<temp;i++) B.clockwise (A, start,temp,i);  for(inti=0;i<=amount-temp;i++) B.anticlockwise (A, start,temp,i); }Else{             for(inti=1;i<=amount-temp;i++) B.anticlockwise (A, start,temp,i);  for(inti=0;i<temp;i++) B.clockwise (A, start,temp,i); }            }}

Sstf

 PackageFour ;Importjava.util.Arrays;ImportJava.util.Scanner;classarray{intlo[]; Boolean[]use;  Public int[] Geta () {returnLo; }     Public voidSetA (int[] a) { This. Lo =A; }     Public Boolean[] Isuse () {returnUse ; }     Public voidSetuse (Boolean[] use) {         This. Use =Use ; }    } Public classSSTF { Public intMin (Array longth,intbegin) {        int[]a =New int[Longth.lo.length];  for(inti=0;i<longth.lo.length;i++) A[i]=math.abs (longth.lo[i]-begin); intb[]=New int[Longth.lo.length];  for(inti=0;i<a.length;i++) B[i]=A[i];//for (int i=0;i<5;i++)//System.out.println ("a-----" +a[i]);Arrays.sort (a);//for (int i=0;i<5;i++)//System.out.println ("b-----" +b[i]);        intc = 0;  for(inti=0;i<longth.lo.length;i++)             for(intj=0;j<longth.lo.length;j++)                if(a[i]==b[j]&&longth.use[j]==false) {System.out.println (longth.lo[j]); C=Longth.lo[j]; LONGTH.USE[J]=true; returnLongth.lo[j]; }                       returnC; }             Public Static voidMain (string[] args) {intstart; System.out.println ("Input read-write header"); Scanner in=NewScanner (system.in); Start=In.nextint (); System.out.println ("Input sequence Length"); intamount; Amount=In.nextint (); Array a=NewArray (); System.out.println ("Input Sequence"); int[]lon=New int[amount]; Boolean[]using=New Boolean[amount];  for(inti=0;i<amount;i++) {Lon[i]=In.nextint (); Using[i]=false;        } A.seta (Lon);        A.setuse (using); SSTF s=NewSSTF ();  for(inti=0;i<amount;i++){            intC=S.min (A, start); Start=B; }                                    }}

Operating system scan algorithm and SSTF algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.