文章分类 -  数据结构与算法

摘要:=0&&$insertVal 阅读全文
posted @ 2013-07-23 02:57 simpman 阅读(92) 评论(0) 推荐(0)
摘要:选择排序:每次找出数列中最小的数,与正确位置的数交换。$arr[$j]){ $minVal = $arr[$j]; $minIndex = $j; } } $temp = $arr[$i]; $arr[$i] = $arr[$minIndex]; $arr[$minIndex... 阅读全文
posted @ 2013-07-23 02:21 simpman 阅读(95) 评论(0) 推荐(0)
摘要:$arr[$j+1]){ $temp = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $temp; } } } } bubbleSort($arr); //输出 print_r($arr);?> 阅读全文
posted @ 2013-07-23 01:57 simpman 阅读(127) 评论(0) 推荐(0)
摘要:约瑟夫问题:n个小孩围成一圈,从第k个小孩开始数,没数到m的小孩出列。问最后剩下的是谁。no = $no; }}$first = null;$n = 4;//表示有几个小朋友$m = 3;$k = 2;/** * addChild函数作用:把$n个小孩构建成一个环形链表, * $first变量指向该环形链表的第一个小孩子。 */function addChild(&$first,$n){ //为什么加地址符 //1.头结点不能动 //内存 ;左堆右栈,中间 全局/静态,文字常量,代码 ;对象实例放在堆内,一般的变量放在栈内;值传递,对象传递,&引用传递。 $cur = null 阅读全文
posted @ 2013-07-23 00:35 simpman 阅读(134) 评论(0) 推荐(0)
摘要:在这些人的叽叽喳喳中,搞定了单链表。no = $no; $this->name = $name; $this->nickName = $nickName; }}class linkList{ public $head = ""; public $cur = ""; public function __construct(){ $this->head = new hero(); } public function addHero($hero=""){ $this->cur = $this->head; wh 阅读全文
posted @ 2013-07-17 11:59 simpman 阅读(127) 评论(0) 推荐(0)
摘要:1 size = $size; 9 }10 11 public function push($item){12 if($this->isFull()){13 return ;14 }15 $this->top++;16 $this->stack[$this->top]=$item;17 }18 19 public function pop(){20 if($this->isEmpty()){21 return ;22 ... 阅读全文
posted @ 2013-07-16 23:50 simpman 阅读(234) 评论(0) 推荐(0)