![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
xijiaoda_liuhao
这个作者很懒,什么都没留下…
展开
-
编写一个程序,把一个有序整数数组放到二叉树中。
/* 编写一个程序,把一个有序整数数组放到二叉树中。 */ void GetTree(int *tree,int low,int high,BTreeNode* &root) { if(low>high) { root=0; return; } int mid=low+(high-low)/2; root=new BTreeNode(tree[mid]); GetTree(t原创 2012-05-10 09:18:23 · 747 阅读 · 0 评论 -
二叉排序树中,令f = (最大值+最小值) / 2,设计一个算法, 找出距离f值最近、大于f值的结点。复杂度不能为O(n2)。
/* 5、二叉排序树中,令f = (最大值+最小值) / 2,设计一个算法, 找出距离f值最近、大于f值的结点。复杂度不能为O(n2)。 */ BTreeNode *GetNode(BTreeNode *root) { BTreeNode *p=root; while(p->pleft!=NULL) { p=p->pleft; } BTreeNode *q=root; whi原创 2012-05-10 09:05:42 · 2047 阅读 · 0 评论 -
给定一个存放整数的数组,重新排列数组使得数组左边为奇数,右边为偶数。 要求:空间复杂度O(1),时间复杂度为O(n)。
/* 给定一个存放整数的数组,重新排列数组使得数组左边为奇数,右边为偶数。 要求:空间复杂度O(1),时间复杂度为O(n)。 */ void GetArray(int *p,int low,int high) { while(low<high) { while(low<high&&p[low]%2!=0) low++; while(low<high&&p[high]%2==0)原创 2012-05-10 09:24:31 · 1063 阅读 · 0 评论 -
判断一个数是不是回文数
#include "stdio.h" bool IsHws(long l) { long a = l; long b = 0; while ( a > 0 ) { int n = a%10; a=a/10; b = b*10+n; } r原创 2013-06-07 17:05:14 · 859 阅读 · 0 评论