-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush_pop.php
More file actions
92 lines (80 loc) · 1.9 KB
/
push_pop.php
File metadata and controls
92 lines (80 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Created by PhpStorm.
* User: 15736
* Date: 2018/8/13
* Time: 10:18
*/
//栈
$arr = [1,2,3];
$array = [];
foreach ($arr as $k => $v){
// if ($k > 1) break;
array_push($array, $v);
}
array_pop($array);
array_pop($array);
//print_r($array);
//队列
$array_other = [];
foreach ($arr as $k => $v){
array_push($array_other, $v);
}
array_shift($array_other);
//print_r($array_other);
//冒泡
function BubbleSort($arr){
$length = count($arr);
if($length<=1) return $arr;
for($i=0;$i<$length;$i++){
for($j=$length-1;$j>$i;$j--){
// echo $arr[$j];die;
if($arr[$j]<$arr[$j-1]){
$tmp = $arr[$j];
$arr[$j] = $arr[$j-1];
$arr[$j-1] = $tmp;
}
}
}
return $arr;
}
//print_r(BubbleSort([5,8,3,9,7]));
//快速排序
function QSort($arr){
$length = count($arr);
if($length <=1){
return $arr;
}
$pivot = $arr[0];//枢轴
$left_arr = array();
$right_arr = array();
for($i=1;$i<$length;$i++){//注意$i从1开始0是枢轴
if($arr[$i]<=$pivot){
$left_arr[] = $arr[$i];
}else{
$right_arr[] = $arr[$i];
}
}
$left_arr = QSort($left_arr);//递归排序左半部分
$right_arr = QSort($right_arr);//递归排序右半部份
return array_merge($left_arr,array($pivot),$right_arr);//合并左半部分、枢轴、右半部分
}
//print_r(QSort([8,5,3,9,7]));
//empty,答案不为空
$float = 0.35;
if (empty($float)){
echo '空';
}else{
echo '不为空';
}
//变量
//$str1 = 'asd';
//$str2 = $str1;
//echo 'str2为:'.$str2.'<br />';
//unset($str1);
//echo 'str2后来为:'.$str2;
$utf = '你好a';
echo strlen($utf);
//var_dump(str_split($utf));
echo mb_substr($utf, 0 ,2);
//在mysql中ALTER TABLE `article` ADD INDEX(`tag`);建立索引,使用explain select tag from article来确定索引是否命中