2019年12月24日

PHP实现观察者模式

摘要: “观察者模式”的观察者三个字信息量很大。玩过很多网络游戏的童鞋们应该知道,即便是斗地主,除了玩家,还有一个角色叫“观察者"。在我们今天他谈论的模式设计中,观察者也是如此。首先,要有一个“主题”。只有有了一个主题,观察者才能搬着小板凳儿聚在一堆。其次,观察者还必须要有自己的操作。否则你聚在一堆儿没事做 阅读全文

posted @ 2019-12-24 23:07 孤灯引路人 阅读(685) 评论(1) 推荐(1) 编辑

拉链法解决hashtable冲突问题

摘要: 拉链法解决冲突。拉链法解决冲突的做法是将所有的相同Hash值的key放在一个链表中,比如key3和key14在hash之后都是0,那么在数组的键为0的地方存储这两个值,形式是链表。如果不能理解我的文字,请看下面的示例,看一下打印信息就明白了。拉链法是什么,就是链表。 class HashNode{ 阅读全文

posted @ 2019-12-24 23:02 孤灯引路人 阅读(1061) 评论(0) 推荐(0) 编辑

php实现hashTable

摘要: Hash表作为最重要的数据结构之一,也叫做散列表。使用PHP实现Hash表的功能。PHP可以模拟实现Hash表的增删改查。通过对key的映射到数组中的一个位置来访问。映射函数叫做Hash函数,存放记录的数组称为Hash表。 Hash函数把任意长度的和类型的key转换成固定长度输出。不同的key可能拥 阅读全文

posted @ 2019-12-24 22:04 孤灯引路人 阅读(451) 评论(1) 推荐(0) 编辑

二叉树遍历

摘要: class Node { public $data; public $left; public $right; public function __construct($data){ $this->data=$data; } } class CreateTree{ public $tree; //二 阅读全文

posted @ 2019-12-24 20:04 孤灯引路人 阅读(140) 评论(0) 推荐(0) 编辑

安装php多进程模块pcntl(一)

摘要: 在使用函数pcntl_fork()时报错 Fatal error: Uncaught Error: Call to undefined function pcntl_fork()....,原因是没有安装pcntl扩展包,有两种解决方式,一种是在编译php的时候加上./configure --enab 阅读全文

posted @ 2019-12-24 16:30 孤灯引路人 阅读(486) 评论(0) 推荐(0) 编辑

单例模式

摘要: 单例模式的定义:保证一个类只有一个实例,并提供一个访问它的全局访问点 class Singleton { //创建静态私有的变量保存该类对象 static private $instance; //防止使用new直接创建对象 private function __construct(){} //防止 阅读全文

posted @ 2019-12-24 11:21 孤灯引路人 阅读(121) 评论(0) 推荐(0) 编辑

循环链表

摘要: class Node{ public $data=null; public $next = null; public function __construct($data=null){ $this->data = $data; } } class LinkdList{ public $header= 阅读全文

posted @ 2019-12-24 10:50 孤灯引路人 阅读(250) 评论(0) 推荐(0) 编辑

双向链表

摘要: class Node{ public $data=null; public $next = null; public $prev=null; public function __construct($data=null){ $this->data = $data; } } class BubbleL 阅读全文

posted @ 2019-12-24 10:48 孤灯引路人 阅读(101) 评论(0) 推荐(0) 编辑

单项链表

摘要: class Node{ public $data=null; public $next=null; public function __construct($data=null){ $this->data = $data; } } class LinkNode{ public $header=nul 阅读全文

posted @ 2019-12-24 08:09 孤灯引路人 阅读(106) 评论(0) 推荐(0) 编辑

[alv]平衡二叉树

摘要: class AVLNode{ public $data; // 节点数据 public $left = null; // 左子结点 public $right = null; // 右子节点 public $bf = 0; // 平衡因子BF public $parent = null; // 存储 阅读全文

posted @ 2019-12-24 08:07 孤灯引路人 阅读(118) 评论(0) 推荐(0) 编辑

大文件归并排序

摘要: //大文件排序 function countsLines($path){ $fd = fopen($path,"r"); $total=0; while(!feof($fd)){ $total++; fgets($fd); } return $total; } $filePath = "./file 阅读全文

posted @ 2019-12-24 08:06 孤灯引路人 阅读(346) 评论(0) 推荐(0) 编辑

快速排序查找匹配元素最前面是否有对应得元素

摘要: $arr = [1,2,3,3,4,5,6]; function binSearch($arr,$num,$start,$end){ if($start > $end){ return -1; } $mid = floor(($start+$end)/2); $midValue = $arr[$mi 阅读全文

posted @ 2019-12-24 00:20 孤灯引路人 阅读(120) 评论(0) 推荐(0) 编辑

二分查找

摘要: $nums = [1, 2, 3, 4, 5, 6]; $num=5; $start = 0; $end = count($nums)-1; echo binary_search($nums,$num,$start,$end); function binary_search($nums,$num,$ 阅读全文

posted @ 2019-12-24 00:19 孤灯引路人 阅读(138) 评论(0) 推荐(0) 编辑

冒泡排序

摘要: $arr = [100,3,5,6,90,10]; for($i=0;$i<count($arr)-1;$i++){ for($j=0;$j<count($arr)-$i-1;$j++){ if($arr[$j] > $arr[$j+1]){ $tmp = $arr[$j]; $arr[$j]=$a 阅读全文

posted @ 2019-12-24 00:18 孤灯引路人 阅读(75) 评论(0) 推荐(0) 编辑

快速排序

摘要: $arr= array(2,13,42,34,56,23,67,365,87665,54,68,3); $info = quick_sort($arr); print_r($info); function quick_sort($arr){ if(count($arr) <= 1){ return 阅读全文

posted @ 2019-12-24 00:16 孤灯引路人 阅读(124) 评论(0) 推荐(0) 编辑

归并排序

摘要: $arr=array(19,7,5,1,3,10); $tmp = mergeSort($arr); print_r($tmp); function mergeSort($arr){ $start = 0; $end = count($arr)-1; if($end == 0){ return $a 阅读全文

posted @ 2019-12-24 00:15 孤灯引路人 阅读(112) 评论(0) 推荐(0) 编辑

选择排序

摘要: $nums = [4, 5, 6, 3, 2, 1]; for($i=0;$i<count($nums);$i++){ $min = $i; for($j=$i+1;$j<count($nums);$j++){ if($nums[$j] < $nums[$min]){ $min = $j; } } 阅读全文

posted @ 2019-12-24 00:13 孤灯引路人 阅读(79) 评论(0) 推荐(0) 编辑

插入排序

摘要: //插入排序 $arr = [2, 3, 1, 6, 4, 7, 5, 9]; for($i=1;$i<count($arr);$i++){ $key = $arr[$i]; $pos = $i; while($pos > 0 && $arr[$pos-1] > $key){ $arr[$pos]= 阅读全文

posted @ 2019-12-24 00:12 孤灯引路人 阅读(90) 评论(0) 推荐(0) 编辑

位图排序

摘要: $bitmap=array_fill(0,1,0); $arr =[1,4,3,6,7]; $size = PHP_INT_SIZE * 8; foreach ($arr as $key => $value){ $index = floor($value/$size); $pos = $value% 阅读全文

posted @ 2019-12-24 00:11 孤灯引路人 阅读(131) 评论(0) 推荐(0) 编辑

导航