Data Structure & algorithm (PhP description) Triple triplet

Source: Internet
Author: User
Tags php source code

Introduction: This is a Data Structure &Algorithm(PhP description) The details page of the triple triplet describes the knowledge, skills, experience, and some PHP Source Code related to PhP.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 339825 'rolling = 'no'>

1 <? PHP
2 /**
3 * triple triplet
4 *
5 */
6 class triplet
7 {
8 private $ _ DATA = NULL;
9
10 // initialize the productkey, devicename, and devicesecret
11 Public Function Init ($ val1, $ val2, $ val3)
12 {
13 $ this-> _ DATA [0] = $ val1;
14 $ this-> _ DATA [1] = $ val2;
15 $ this-> _ DATA [2] = $ val3;
16 return true;
17}
18
19 // destroy the productkey, devicename, and devicesecret
20 public function destroy ()
21 {
22 unset ($ this-> _ data );
23 return true;
24}
25
26 // return the value of $ key
27 public function get ($ key)
28 {
29 if ($ key <1 | $ key> 3) return false;
30 return $ this-> _ DATA [$ key-1];
31}
32
33 // set the value of $ key to $ Val
34 public function put ($ key, $ Val)
35 {
36 if ($ key <1 | $ key> 3) return false;
37 $ this-> _ DATA [$ key-1] = $ val;
38 return true;
39}
40
41 // sort by Ascending Order
42 Public Function isascending ()
43 {
44 return ($ this-> _ DATA [0] <= $ this-> _ DATA [1]) & ($ this-> _ DATA [1] <= $ this-> _ DATA [2]);
45}
46
47 // sort by descending order
48 Public Function isdescending ()
49 {
50 return ($ this-> _ DATA [0] >=$ this-> _ DATA [1]) & ($ this-> _ DATA [1] >=$ this-> _ DATA [2]);
51}
52
53 // obtain the maximum value
54 public function max ()
55 {
56 return ($ this-> _ DATA [0] >=$ this-> _ DATA [1])? ($ This-> _ DATA [0] >=$ this-> _ DATA [2])? $ This-> _ DATA [0]: $ this-> _ DATA [2]: ($ this-> _ DATA [1] >=$ this-> _ DATA [2])? $ This-> _ DATA [1]: $ this-> _ DATA [2];
57}
58
59 // obtain the minimum value
60 public function min ()
61 {
62 Return ($ this-> _ DATA [0] <= $ this-> _ DATA [1])? ($ This-> _ DATA [0] <= $ this-> _ DATA [2])? $ This-> _ DATA [0]: $ this-> _ DATA [2]: ($ this-> _ DATA [1] <= $ this-> _ DATA [2])? $ This-> _ DATA [1]: $ this-> _ DATA [2];
63}
64}
65
66 //
67 $ objtriplet = new triplet ();
68 echo "init:"; var_dump ($ objtriplet-> Init (1, 2, 3); echo "<br/> ";
69
70 echo "get 1:"; var_dump ($ objtriplet-> get (1); echo "<br/> ";
71 echo "get 4:"; var_dump ($ objtriplet-> get (4); echo "<br/>"; // false
72 echo "put 3, 4:"; var_dump ($ objtriplet-> put (3, 4); echo "<br/> ";
73
74 echo "MAX:"; var_dump ($ objtriplet-> MAX (); echo "<br/> ";
75 echo "Min:"; var_dump ($ objtriplet-> min (); echo "<br/> ";
76
77 echo "isascending:"; var_dump ($ objtriplet-> isascending (); echo "<br/> ";
78 echo "isdescending:"; var_dump ($ objtriplet-> isdescending (); echo "<br/> ";
79?>

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/339825.html pageno: 7.

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.