自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

borderLands

step by step

  • 博客(37)
  • 收藏
  • 关注

原创 双链表 double linked list

double linked list

2015-08-23 22:27:26 601

原创 循环链表的实现 (circularly linked list)

节点,和circularly list类C_list:typedef struct Node{ int key; struct Node *next;}Node,*pNode;typedef struct C_list{ pNode lastNode; C_list(); void insertAfter(Node &nod, Node &x);

2015-08-20 17:14:44 439

原创 用list实现桶排序

/**8/4/2015 更新 *桶的数目为array的长度n *见8.4 bucket sort int n = x.size(); int max = x.front(); int min = x.front(); for(int i = 0; i < n; i++){ if(x[i] > max) max =

2015-07-28 10:11:47 351

原创 扩充的数据结构-区间树interval-tree

(1)区间树所存的value为一个区间interval,其key值为interval的low值(即左值,由于树有左右节点,interval由low,high决定,避免混淆)(2)区间树还储存某节点 x 的所有子节点中最大值m,即m = m[x], or m = m[x->left], or m = m[x->right.m所带来的modifier操作的修改:旋转操作:pnode

2015-07-24 23:24:59 513

原创 约瑟夫问题循环链表解法、队列解法

(1)单链表解法:typedef struct node{ //定义单链表结构,next指向下一个节点 int key; node *next;}node,*pnode;void test(){ int n,m; cout>n; cout>m; cout<<"the kill list is: "; pnode ptr = (

2015-07-24 21:12:30 743

原创 red-black tree的删除节点算法

对于bst的tree_delete算法,若被删除节点 y 为黑色,那么 y 的替代者 x 节点的所有path都少了一个black-height高度。我们假定:node x has an "extra" black. 即:将 y 的blackness "push" 到它的子节点 x 身上。因此,x 节点是“双黑”或者“红-黑”。idea: move the extra black up th

2015-07-23 16:10:12 481

原创 对binary-search-tree的tree-delete算法的更正

bst树的删除算法更正

2015-07-23 11:17:03 333

原创 扩充的数据结构-Order Statistic Tree

(1)以红黑树作为underlying data structure,在树的每个节点增加一个int域储存该节点的subtree节点个数(包含自身)node_size(x) = node_size(left[x]) + node_size(right[x]) + 1;设nil节点的node_size返回0;typedef struct node{ int key; int

2015-07-21 11:03:43 765

转载 struct与class的区别

转载来源:http://blog.sina.com.cn/s/blog_48f587a80100k630.htmlC++中的struct对C中的struct进行了扩充,它已经不再只是一个包含不同数据类型的数据结构了,它已经获取了太多的功能。struct能包含成员函数吗? 能!struct能继承吗? 能!!struct能实现多态吗? 能!!! 既然这些它都能实现,那它和c

2015-07-21 11:01:27 362

原创 红黑树red-black-tree

(1)红黑树是在BST的基础上增加了一个color信息:用int color = 1代表黑色,int color = 0代表红色;(2)Rotation:void left_rotate(pnode &x){ if(x != nil){ pnode y = x->right; x->right = y->left; if(y->lef

2015-07-20 18:29:24 289

原创 正确的binary search tree -- 非递归插入

(1)定义一个链表式结构体,作为bst的节点node,key值为int(注意不要用string类作为后续red-black tree的color,?为什么不清楚?)typedef struct node{ int key; /*int color;*/ struct node *left; struct node *right; struct node *p;}*p

2015-07-20 17:56:17 436

转载 约瑟夫问题

对于约瑟夫问题,今天看到了一篇好帖子,是用数学方法处理的,感觉还不错的无论是用链表实现还是用数组实现都有一个共同点:要模拟整个游戏过程,不仅程序写起来比较烦,而且时间复杂度高达O(nm),当n,m非常大(例如上百万,上千万)的时候,几乎是没有办法在短时间内出结果的。我们注意到原问题仅仅是要求出最后的胜利者的序号,而不是要读者模拟整个过程。因此如果要追求效率,就要打破常规,实施一点数学

2015-07-19 14:57:30 353

原创 用linked list实现binary-search-tree及其inorderwalk(中序遍历)

binary-search-tree, 结构体struct实现linked list

2015-07-16 12:10:38 388

原创 map练习-Lexicon词典-anagram游戏

static string character_sort(string str){ for(int i = 0; i < str.size()-1; i++){ int j = i; int key = str[i+1]; while(str[j] > key && j >= 0){ str[j+1] = str[j]

2015-07-11 18:15:53 486

原创 map

map: associative containers, key-value. the keys are generally used to sort and uniquely identify the elements, while the mapped values are content associated to this key.1、insert方法: my_map.inser

2015-07-10 14:37:59 278

原创 lambda function的用法

建立一个闭包(closure):一个匿名函数对象,能够捕获局域内变量。 语法: [capture-list] ( params ) mutable(optional) exception attribute -> ret{body} //完整定义 解释:1、(params):参数,相当于function的参数,例:auto y = [](int i){ return i; };c

2015-07-09 20:30:30 1715

转载 c++11版本list中sort用lambda表达式

//定义学生类class Student{public:string StuName; //姓名string StuNum; //学号string Sex; //性别//成绩float English; //英语float SQL; //SQLfloat Prob; //概率论float Circuit; //电路float CSharp; //C#

2015-07-09 15:47:44 4267

原创 用结构体struct(数组)实现桶排序

#include #include "hello.h"#include "list"#include "console.h"#include "random"#include "time.h"#include "string.h"using namespace std;typedef struct{ int node[10]; int count;}*pBarr

2015-07-09 15:31:58 675

原创 c++链表std::list

Lists are sequence containers that allow constant time insert and erase operations. 比起其他序列容器,例如:array、vector、deque等,list的优点是能在容器内的任意位置插入、取出、移动元素。list主要的缺点是缺少直接通往元素位置的接口。(The main drawback of list and

2015-07-08 14:13:25 500

原创 LaTeX练习

limx→0(1−x)1x=e\lim\limits_{x\to 0}(1-x)^{\frac 1x} = e ∑i=0ni2=n(n+1)(2n+1)6(display)\sum_{i=0}^ni^2 = \frac{n(n+1)(2n+1)}6\tag{display} ι\iota 希腊字母读法 Αα:阿尔法 Alpha Ββ:贝塔 Beta Γγ:伽玛 Gamma Δ

2015-06-24 23:12:23 694

原创 机器学习与数据挖掘1

learning problem-outline:example: predicting how a viewer will rate a moviethe essence of machine learning: 1. A pattern exists; 2. We can't pin it down mathematically; 3. we have data on it.lea

2015-06-24 08:59:14 251

原创 almostSorted

(1) 90% sorted problem设输入序列为A,有n个元素。DEFINITION: A is 90% sorted:if 10% elements are removed, then the remaining 90% elements are sorted. 判断A是否90%sorted: 1. 如果A是已排好序列,那么return true 2. 如果A不是90%sorted,

2015-06-23 11:14:54 380

原创 《设计模式》学习体会

《Design Patterns: Elements of Reusable Object-Oriented Software》

2015-06-13 20:40:09 368

原创 LawOfLargeNumbers

LLN: A theorem describes the results of performing thesame experiment a large number times.According to the law, the average of the results from large number times of trials should be close to

2015-06-12 21:23:17 310

原创 求primes的算法

primes算法,总结了用定义和合数引理判断质数的方法,并且利用建立bool型数组筛选得到质数的真值数组。

2015-06-12 20:25:50 567

原创 ctime学习

static void test(void){ struct tm *timeinfo; time_t now; time(&now); timeinfo = localtime(&now); timeinfo->tm_year = 2015-1900; timeinfo->tm_mday = 13; long oneday_sec = dif

2015-06-12 17:56:21 279

原创 为什么使用快排?

快排的速度只比插入排序快?如何选择好的pivot?

2015-06-12 08:23:43 508

原创 在数组A中寻找第k小的元素-最坏情况为线性时间的算法

I : 平均情况下的时间复杂度为:O(n) 期望值(expected); 最坏情况下的时间复杂度为:O(n的平方)即:每次对A划分为(0:n-1)函数命名为:find_k_th(A, p, q, k)    //int  value = find_k_th(A, p, q, k): value为从A[p]到A[q]中第k小的值可以从 random-quicksort 算法中(复杂度分析运用

2015-06-08 19:10:34 875

原创 radix-sort基数排序 内部排序用count-sort

int radix_count_sort(int *A, int *d, int n){ //inner: count-sort int temp[n]; int k = 10; int Counter[k]; int i = 0, j = 0; for(i = 0; i < k; i++) Counter[i] = 0; fo

2015-06-07 20:43:39 509

原创 线性时间排序-counting_sort

int count_sort(int *A, int n, int k){ int B[n]; int C[k+1]; for(int i = 0; i < k+1; i++) //initialize C[i]: A的每个值有0个 C[i] = 0; for(int i = 0; i < n; i++){ //将A的每个值的出现频率

2015-06-06 21:33:29 343

原创 堆排序heapsort

int heapsort(int *A, int n){ int i = 0; int count = n; build_heap(A, n); for(i = n; i > 0; i--){ int temp = A[0]; A[0] = A[i-1]; A[i-1] = temp; count--;

2015-06-06 17:44:52 292

原创 建立一个堆结构heap-build

int max_heapify(int *A, int i, int n){ int left = 2*i; int right = 2*i+1; int largest = i; if( A[ left-1 ] >= A[ i-1 ] && left <= n ) largest = left; if( A[ right-1 ] >= A

2015-06-06 15:54:37 2111

原创 Joseph队列解法

int main(){ while(true){ int a = 0, b = 0; int numOfPeople = 0, numToSpare = 0; cout<<"input number of people:"; cin>>numOfPeople; cout<<"input number to s

2015-06-02 22:48:49 458

原创 快排的随机化算法

int randQuickSort(int *x, int p, int q){ if(p < q){ int rand_n = rand()%(q-p+1); //随机化选择交换pivot的位置 int temp = x[rand_n]; x[rand_n] = x[p]; x[p] = temp;

2015-05-31 20:24:21 393

原创 合并排序

int test(void){ int x[] = {3,2,1,6,3,7,5,1,9,21,97,32,5,4}; int n = (sizeof x)/4; mergeSort(x,0,n-1); for(int i = 0; i < n; i++) cout<<x[i]<<endl; return 0;}int mergeSor

2015-05-31 16:01:52 361

原创 快排

int part(int *x, int p, int q){ int pivot = x[p]; int i = p; int j = p+1; int temp = 0; for(j = p+1; j <= q; j++){ if(x[j] < pivot){ i++; temp = x[i

2015-05-31 15:12:23 310

原创 question1-在插入排序中运用二元搜索代替线性查找

插入排序,递归二元搜索

2015-05-31 14:35:20 549 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除