According to the keyword based on the sorting method, there are MSD and LSD two kinds of schemes. Among them, the LSD scheme is very special, suitable for multiple keywords, only through the allocation and collection can complete the sorting.
LSD First group position is already lined up, and then start with a low keyword, the final high keyword will be the leading role; you can split the keyword
Use the LSD scheme to repeatedly assign and collect sorting methods. The use of linked lists reduces the amount of memory consumed during sorting.
Import java.util.LinkedList;
Import Com.sun.org.apache.regexp.internal.REUtil;
Class card{private int type;//color public int GetType () {return type;} public void SetType (int type) {this.type = type; public int GetPoint () {return point;} public void setpoint (int point) {this.point = point;} private int point;//value PU Blic Card (int type,int point) {this.type=type; This.point=point} public String toString () {return "(" +type+ "," +point+ "
)"; } public class Cardmulkeysort {public static enum Typeenum {Red,block,plum_blossom,spade;/* More Highlights: Http://www.bianceng . cnhttp://www.bianceng.cn/programming/sjjg/*/public static int valueof (Typeenum x) {for (int i = 0; i < Typeenum . values (). length;
i++) {if (x==typeenum.values () [i]) {return i;}
} return-1; }/** * Sort, a static method static{content} is generated when the class is instantiated/@SuppressWarnings ("unchecked") static void Raidsort (linkedlist<card> LST) {//grouping low keywords linkedlist[] rd=new linkedlist[10];//assumed values from 1 to ten for (int i=0;i<rd.length;i++) Rd[I]=new LinkedList ()//per value specific how many uncertainties//bar LST elements are removed into the corresponding group while (Lst.size () >0) {card t=lst.remove ();//deleted header element rd[
T.getpoint () -1].add (t);//Add to the end of the list of the groups, point from 1 to 10, array from 0 to 9}//collect for (int i = 0; i < rd.length; i++) {Lst.addall (rd[i]);}
Grouping high key words rd=new linkedlist[4];
for (int i=0;i<rd.length;i++) rd[i]=new linkedlist ();
while (Lst.size () >0) {card t=lst.remove ()//deleted header element Rd[t.gettype ()].add (t);//Add to the end of the list of the groups, point from 1 to 10, array from 0 to 9}//Collect
for (int i = 0; i < rd.length i++) {lst.addall (rd[i]);} /** * @param args */public static void main (string[] args) {linkedlist<card> lst=new linkedlist<card> (); LST
. Add (New Card (typeenum.valueof (Typeenum.block), 5));
Lst.add (new Card (typeenum.valueof (typeenum.red), 5));
Lst.add (new Card (typeenum.valueof (Typeenum.block), 7));
Lst.add (new Card (typeenum.valueof (Typeenum.block), 3));
Lst.add (new Card (typeenum.valueof (Typeenum.block), 5));
Lst.add (new Card (typeenum.valueof (Typeenum.spade), 5)); Lst.add (new card (typeenum.valueof TypeenUm.spade), 9);
Lst.add (new Card (typeenum.valueof (typeenum.red), 5));
Lst.add (new Card (typeenum.valueof (Typeenum.plum_blossom), 6));
SYSTEM.OUT.PRINTLN (LST);
Raidsort (LST);
SYSTEM.OUT.PRINTLN (LST); }
}
Author: csdn Blog u010026901