Sort _ Simple Sort _ Insert Sort _ Object Sort

Source: Internet
Author: User

 Public classPerson {PrivateString LastName; PrivateString FirstName; Private intAge ;  PublicPerson (String last,string First,inta) {LastName=Last ; FirstName=First ; Age=A; }     Public voidDisplayperson () {System.out.print ("Last Name:" +lastName); System.out.print (", First name" +firstName); System.out.println (", Age:" +Age ); }     PublicString GetLast () {returnLastName; }}
 Public classArrayinob {PrivatePerson a[]; Private intNelems;  PublicArrayinob (intmaxSize) {a=NewPerson[maxsize]; Nelems=0; }    //Insert     Public voidInsert (String last,string First,intAge ) {A[nelems++]=NewPerson (last, first, age); }    //Show     Public voiddisplay () { for(intj=0;j<nelems;j++) A[j].displayperson ();    System.out.println (); }    //Sort     Public voidInsertionsort () {intOut,in;  for(out=1;out<nelems;out++) {Person temp=A[out]; Inch=Out ; //sort the last name             while(In>0 && a[in-1].getlast (). CompareTo (Temp.getlast ()) >0) {A[in]=a[in-1]; Inch--; } A[in]=temp; }    }}
 Public classTest { Public Static voidMain (string[] args) {intmaxsize=100; Arrayinob Array=NewArrayinob (maxSize); Array.insert ("Evans", "Patty", 24); Array.insert ("Smith", "Lorraine", 37); Array.insert ("Smith", "Tom", 43); Array.insert ("Smith", "Henry", 63); Array.insert ("Yee", "Sato", 21); Array.insert ("Hashimoto", "Henry", 29); Array.insert ("Stimson", "Ming", 72); Array.insert ("Velasquez", "Rong", 54 ); Array.insert ("Vang", "Qian", 22);            Array.display ();        Array.insertionsort ();    Array.display (); }}

Sort _ Simple Sort _ Insert Sort _ Object Sort

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.