PackageCom.example.demo;/*** * <p>description: Stack function simulation--Array </P> * @ClassName: Stackx * * Stack LIFO feature *@authorFeng Hao April 23, 2018 Morning 11:29:50 *@seeTODO*/ Public classStackx {Private intmaxSize; Private Char[] stackarray; Private inttop; PublicStackx (intmax) { This. maxsize=Max; Stackarray=New Char[MaxSize]; Top=-1; } Public voidPushCharLthrowsException {if(!Isfull ()) {stackarray[++top]=l; }Else { Throw NewException (); } } Public CharPop ()throwsException {if(!IsEmpty ()) { returnstackarray[top--]; }Else { Throw NewException (); } } Public CharPeek () {returnStackarray[top]; } Public BooleanIsEmpty () {return(Top==-1); } Public BooleanIsfull () {return(top==maxsize-1); } Public Static voidMain (string[] args)throwsException {String AAA= "Fenghao"; Stackx Stack=NewStackx (Aaa.length ()); for(inti = 0; I < aaa.length (); i++) { CharCharAt =Aaa.charat (i); Stack.push (charAt); } for(inti = 0; I < aaa.length (); i++) {System.out.println (Stack.pop ()); } } }
PackageCom.example.demo;/*** * <p>description: Queue Writing </P> * @ClassName: Queues *@authorFeng Hao April 23, 2018 afternoon 3:46:14 *@seeTODO*/ Public classQueues {Private intmaxSize; Privatelong[] Quearray; Private intFront; Private intRear; Private intNitems; PublicQueues (ints) { This. maxsize=s; Quearray=NewLong[maxsize]; This. front=0; This. rear=-1; This. nitems=0; } Public voidInsert (Long s) {if(rear==maxsize-1) {Rear=-1; } quearray[++rear]=s; Nitems++; } Publiclong Remove () {long x=quearray[front++]; Quearray[front++]=NULL; if(front==maxSize) {Front=0; } nitems--; returnx; } Public Static voidMain (string[] args) {/*BigDecimal a = new BigDecimal ("10"); BigDecimal B = New BigDecimal ("3"); System.out.println (A.divide (b,2,2). toString ());*/ }}
Joseph Question Code
PackageCom.example.demo;Importjava.util.ArrayList;Importjava.util.List;/*** * <p>description: Joseph question </P> * @ClassName: Yuesefu *@authorFeng Hao April 24, 2018 Morning 10:38:49 *@seeTODO*/ Public classYuesefu { Public Static voidYuesefu (intTotalnum,intcountnum) { //number of people initializedlist<integer> start =NewArraylist<integer>(); for(inti = 1; I <= totalnum; i++) {start.add (i); } //counting starting from the first K intK = 0; while(Start.size () >0) {k= k +Countnum; //index position of person mk = k% (Start.size ())-1; System.out.println (String.Format ("K%s Size%s", K,start.size ())); //Judging whether to the end of the team if(K < 0) {System.out.println (Start.get (start.size ()-1)); Start.remove (Start.size ()-1); K= 0; } Else{System.out.println (Start.get (k)); Start.remove (k); } } } Public Static voidMain (string[] args) {Yuesefu.yuesefu (41, 3);//int a=3%1;//System.out.println (a); }}
Online address
Data structures and Algorithms (ii)