PHP number 3 Drop 1 Object-oriented writing & lt ;? Php uses the object-oriented method to write the monkey Dawang to implement the same number 3 return 1 classMonkey {*** define monkey class * attribute number $ id PHP number 3 return 1 Object-oriented writing
Add () ;}// function add () {$ m = new Monkey (); $ m-> id = $ this-> ct; if ($ this-> ct = 0) {$ this-> first = $ m; $ this-> last = $ m; $ m-> left = $ m; $ m-> right = $ m;} else {$ this-> last-> right = $ m; $ m-> left = $ this-> last; $ m-> right = $ this-> first; $ this-> first-> left = $ m; $ this-> last = $ m ;} $ this-> ct ++;} // monkey deletion method function del ($ m) {if ($ this-> ct <= 0) {return ;} else if ($ this-> ct = 1) {$ this-> first = $ This-> last = null;} else {$ m-> left-> right = $ m-> right; $ m-> right-> left = $ m-> left; if ($ m = $ this-> first) {$ this-> first = $ m-> right;} else if ($ m = $ this-> last) {$ this-> last = $ m-> left ;}$ this-> ct --;}} /* the code here is to make 500 monkeys stand in a circle and then return one by three until there is one to print out the monkey's number. */$ Circle = new circle (500 ); $ number = 0; $ mk = $ circle-> first; while ($ circle-> ct> 1) {$ number ++; if ($ number = 3) {$ number = 0; $ circle-> Del ($ mk) ;}$ mk = $ mk-> right;} echo $ circle-> first-> id;?>