
数据结构与算法
blueboy82006
孤独漂泊在程序海洋中的小浦原
展开
-
排序算法之希尔排序
//ShellSort 希尔排序void ShellSort(int A[],int n){ int i,j,gap; int temp; gap=n/2; while(gap>0) { for(i=gap;i<n;i++) { temp=A[i]; j=i-gap; while(j>=0 && temp<A[j]) {原创 2010-02-08 20:09:00 · 581 阅读 · 1 评论 -
findMaxDistance
int BTNodeDepth(BTNode *b){ int lchilddep,rchilddep; if(b==NULL) return 0; else { lchilddep=BTNodeDepth(b->lchild); rchilddep=BTNodeDepth(b->rchild); r原创 2012-02-17 20:16:27 · 750 阅读 · 0 评论 -
CreateBTfromPre
BTNode *CreateBTfromPre(char *pre,char *in,int n,int m){ BTNode *s; char *p,*q,*minp; int minpre,minin ,k; if(n<=0) return NULL; minpre=m+1; for(p=in;p<in+n;p++) for(q原创 2012-02-15 16:52:59 · 731 阅读 · 0 评论 -
insertNew
void insertNew(BTNode *tree, BTNode *new_node){ int llcnt(0),lrcnt(0),rrcnt(0); BTNode *lch,*rch,*p,*lb; if(tree->lchild==NULL)//insert tree->lchild=new_node; else if(tree->rc原创 2012-02-15 15:46:44 · 649 阅读 · 0 评论 -
CreatBT
BTNode *CreatBT(char *post,char *in,int n,int m){ BTNode *s; char *p,*q,*maxp; int maxpost,maxin ,k; if(n<=0) return NULL; maxpost=-1; for(p=in;p<in+n;p++) for(q=post;q<post+m;q++) if(*p==原创 2012-02-15 14:31:38 · 640 阅读 · 0 评论 -
find_mid
int find_mid( int *a, int *b, int length){ if (length == 1)//这里应该根据中位数的定义取大小 return a[0]<b[0]?a[0]:b[0]; int i = length/2; if (a[i] == b[i]) return a[i]; else if (a[i原创 2012-02-15 14:04:34 · 583 阅读 · 0 评论 -
中国剩余定及由此解决的一个问题
我国古代数学名著《孙子算经》中,记载这样一个问题: “今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何。”用现在的话来说就是:“有一批物品,3个3个地数余2个,5个5个地数余3个,7个7个地数余2个,问这批物品最少有多少个?” 这个问题的解题思路,被称为“孙子问题”、“鬼谷算”、“隔墙算”、“韩信点兵”等等.那么,这个问题怎呢?明朝数学家程大位把这一解法编成四句歌诀: 三人转载 2010-03-07 10:58:00 · 1077 阅读 · 0 评论 -
八皇后问题的C语言实现
问题就不描述了,直接上代码: #includeint chess[8][8]={0};int a[8],b[15],c[15];int sum=0; //统计所有摆法void PutQueen(int n){ int col,i,j; for(col=0;col<8;col++原创 2010-02-26 15:58:00 · 17308 阅读 · 4 评论 -
折半插入排序算法
//折半插入排序算法void BiInsertSort(int *Data,int n){ int i,j,low,high,mid,temp; for(i=1;i<n;i++)//先确定第i个元素应插入的位置 { temp=Data[i]; low=0,high=i-1; while(low<=high) { mid=(low+high)/2;原创 2010-02-26 16:06:00 · 921 阅读 · 0 评论 -
排序算法之简单排序
//冒泡排序算法void BubbleSort(int *Data,int n) { int i,j,temp; bool exchange; for(i=n-1,exchange=true;i>0 && exchange;i-- ) { for(j=0,exchange=false;j<i;j++) { if(Data[j+1]<Data[j原创 2010-02-26 16:03:00 · 816 阅读 · 0 评论 -
计算二叉树中叶子结点数的算法
//计算树中叶子结点数int LeafNodes(BTNode *b){ int num1,num2; if(b==NULL) return 0; else if(b->lchild==NULL && b->rchild==NULL) return 1; else { num1=LeafNodes(b->lchild); num2=LeafNodes原创 2010-02-16 21:49:00 · 18574 阅读 · 0 评论 -
计算二叉树中双分支结点数的算法
//计算树中双分支结点数int DBranchNodes(BTNode *b){ int num1,num2,n; if(b==NULL) return 0; else if(b->lchild==NULL || b->rchild==NULL) n=0; else n=1; num1=DBranchNodes(b->lchild); num2=原创 2010-02-16 21:48:00 · 4755 阅读 · 0 评论 -
计算二叉树中所有结点数的算法
//计算树中所有结点数int Nodes(BTNode *b){ int num1,num2; if(b==NULL) return 0; else { num1=Nodes(b->lchild); num2=Nodes(b->rchild); return (num1+num2+1); }}原创 2010-02-16 21:46:00 · 4555 阅读 · 1 评论 -
二叉树深度算法
//树深度算法int BTNodeDepth(BTNode *b){ int lchilddep,rchilddep; if(b==NULL) return 0; else { lchilddep=BTNodeDepth(b->lchild); rchilddep=BTNodeDepth(b->rchild); return (lchilddep>rc原创 2010-02-16 21:45:00 · 1024 阅读 · 0 评论 -
计算二叉树中分支结点数的算法
//计算树中分支结点数int BranchNodes(BTNode *b){ int num1,num2,n; if(b==NULL) return 0; else if(b->lchild==NULL && b->rchild==NULL) n=0; else n=1; num1=BranchNodes(b->lchild); num2=Bra原创 2010-02-16 21:47:00 · 6315 阅读 · 1 评论 -
排序算法之二路归并排序
//MergeSort 二路归并排序void Merge(int A[],int low,int mid,int high){ int *A1; int i=low,j=mid+1,k=0; A1=(int *)malloc((high-low+1)*sizeof(int)); while(i<=mid && j<=high) if(A[i]<A[j]) A1原创 2010-02-12 20:40:00 · 784 阅读 · 0 评论 -
排序算法之快速排序
//QuickSort 快速排序void QuickSort(int A[],int low,int high){ int i=low,j=high; int temp; if(low<high) { temp=A[low]; while(i!=j) { while(j>i && A[j]>temp) j--; if(i<j)原创 2010-02-09 00:09:00 · 517 阅读 · 1 评论 -
排序算法之堆排序
//HeapSort 堆排序void Sift(int A[],int low,int high){ int i=low,j=2*i; int temp=A[i]; while(j<=high) { if(j<high && A[j]<A[j+1]) j++; if(temp<A[j]) { A[i]=A[j]; i=j;原创 2010-02-10 20:18:00 · 910 阅读 · 0 评论 -
void CBTInsert(BTNode *tree, BTNode *new_node)
void CBTInsert(BTNode *tree, BTNode *new_node){ int llcnt(0),lrcnt(0),rrcnt(0); BTNode *lch,*rch,*p,*lb; if(tree->lchild==NULL)//insert tree->lchild=new_node; else if(tree->rc原创 2012-05-01 22:24:51 · 1301 阅读 · 0 评论