上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页

2012年9月8日

堆排序

摘要: //堆排序#include <iostream.h>void main(){ int a[12]={2,4,6,34,31,24,65,37,87,68,90,23}; int b[12]; for (int i=0;i<12;i++) { b[i]=a[i]; int temp=i; while (temp-1>=0) { if (b[(temp-1)/2]<b[temp]) { int x=b[(temp-1)/2]; ... 阅读全文

posted @ 2012-09-08 11:54 为梦飞翔 阅读(215) 评论(0) 推荐(0)

2012年9月6日

基数排序

摘要: //基数排序#include<iostream.h>void funCount(int *count,int* a,int length,int num)//对应位上数字的个数{ for (int i=0;i<length;i++) { int x=a[i]; for (int j=2;j<=num;j++) { x=x/10; } x=x%10; count[x]++; }}void funIndex(int* count,int* index)//对应位上数字开始存放... 阅读全文

posted @ 2012-09-06 15:32 为梦飞翔 阅读(308) 评论(0) 推荐(0)

寻找第K小值

摘要: #include<iostream.h>int findValue(int k,int* a,int start,int end){ int low=start; int high=end; int x=a[start]; int flag=0; while (low!=high) { if (flag==0) { for (int j=high;j>=low;j--) { if (a[j]<x) { ... 阅读全文

posted @ 2012-09-06 10:15 为梦飞翔 阅读(212) 评论(0) 推荐(0)

快速排序

摘要: //快速排序算法#include<iostream.h>void sort(int start,int end,int *a){ if (start>=end) return; int low=start; int high=end; int x=a[start]; int flag=0; while (low!=high) { if (flag==0)//左边空,从右向左找比x小的值 { for(int j=high;j>=low;j--) { ... 阅读全文

posted @ 2012-09-06 09:17 为梦飞翔 阅读(204) 评论(0) 推荐(0)

2012年9月4日

查找算法:

摘要: //顺序查找:技巧,卫兵法,在查找的线性表后加入要查找的元素while(a[i]!=x) i++;return i;//折半查找:low height mid O(log n);//索引分块:把值的范围分成若干个区域,每个区域对应着起始的下标//二叉排序树:动态查找,找不到插入该节点,特点,插入的点时叶子p=tree;parent=NULL;while(p){ if(p->element=key) break; if(p->element>key) parent=p;p=p->pLchild; if(p->element<key) parent=p;p=p- 阅读全文

posted @ 2012-09-04 22:51 为梦飞翔 阅读(279) 评论(0) 推荐(0)

2012年9月2日

树的孩子兄弟表示法

摘要: typedef struct DataType {}DataType;typedef struct Node { DataType element; struct Node * pFirstChild; struct Node * pNextSibling;}*Tree,*Queue;树的先序递归遍历:void TraverseTree(Tree p){ if(p==NULL) return; cout<<p->element<<endl; TraverseTree(p->pFirstChild); TraverseTree(p->pNextSibli 阅读全文

posted @ 2012-09-02 22:31 为梦飞翔 阅读(10908) 评论(1) 推荐(2)

2012年8月27日

找出所有和模式串匹配的字符串的起始下标

摘要: /*找出所有和模式串匹配的字符串的起始下标*/#include <iostream>using namespace std;void getNext(char *p,int *next){ int j,k; next[0]=-1; j=0; k=-1; while(j<strlen(p)-1) { if(k==-1||p[j]==p[k]) //匹配的情况下,p[j]==p[k] { j++; k++; next[j]=k; } e... 阅读全文

posted @ 2012-08-27 10:00 为梦飞翔 阅读(482) 评论(0) 推荐(0)

2012年8月26日

KMP算法next数组的求法

摘要: 按照递推的思想: 根据定义next[0]=-1,假设next[j]=k, 即P[0...k-1]==P[j-k,j-1] 1)若P[j]==P[k],则有P[0..k]==P[j-k+1,j],很显然,next[j+1]=next[j]+1=k+1; 2)若P[j]!=P[k],则可以把其看做模式匹配的问题,即匹配失败的时候,k值如何移动,显然k=next[k]。void getNext(char *p,int *next){ next[0]=-1; next[1]=0; for (int i=2;i<strlen(p);i++) { int j=i-1;... 阅读全文

posted @ 2012-08-26 21:40 为梦飞翔 阅读(1347) 评论(0) 推荐(0)

2012年8月25日

汉诺塔递归和非递归算法实现

摘要: /*汉诺塔递归和非递归算法实现*/#include <iostream>using namespace std;void fun(int N,char a,char b,char c)//递归算法{ if (N==1) { cout<<a<<"-->"<<c<<endl; return; } fun(N-1,a,c,b); cout<<a<<"-->"<<c<<endl; fun(N-1,b,a,c);}void main(){ fun 阅读全文

posted @ 2012-08-25 20:07 为梦飞翔 阅读(4414) 评论(0) 推荐(0)

2012年8月24日

用队列生成杨辉三角

摘要: /*用队列生成杨辉三角*/#include <iostream>using namespace std;typedef struct Node{ int element; Node* pNext;}Node,*LinkList;typedef struct { LinkList head; LinkList tail;}Queue;void InitQueue(Queue& queue){ queue.head=(LinkList)malloc(sizeof(Node)); queue.head->pNext=NULL; queue.tail=que... 阅读全文

posted @ 2012-08-24 22:31 为梦飞翔 阅读(705) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 13 14 下一页

导航