
数据结构和算法
fertiland
喜欢旅行,爬山,慢跑
电影,音乐
展开
-
二叉查找树(BST)---创建 清空 遍历
#include iostream>#include queue>#include stdlib.h>using namespace std;//定义树结构typedef struct tree_node_tag...{ int value; struct tree_node_tag *left; struct tree_node_tag *right;} TreeNode;原创 2007-10-21 11:13:00 · 1393 阅读 · 1 评论 -
二叉查找树(BST)---拷贝 相等判断 查找节点 统计节点 统计层数 判断BST
//拷贝树void copy_tree(TreeNode *&dst,TreeNode *src) ...{ if( NULL==src) dst= NULL ; else ...{ dst=(TreeNode *) malloc(sizeof(TreeN原创 2007-10-22 09:31:00 · 1259 阅读 · 0 评论 -
二叉查找树(BST)---删除节点
TreeNode* min_node(TreeNode *t)...{ if (t == NULL) ...{ return NULL; } if (t->left != NULL) ...{ return min_node(t->left); }else...{ return t; }}void rem_node(原创 2007-10-22 08:15:00 · 2638 阅读 · 0 评论 -
和式分解--递归设计
Csdn上的一个问题程序运行: 输入n,输出其和等于n的所有不增的正整数和式。例如,n=4,程序将输出: 4=4; 4=3+1 4=2+2 4=2+1+1 4=1+1+1+1 但如果用递归方法 算法: 递归函数设置两个参数:参数i是本次递归调用要分解的数,参数原创 2007-10-24 11:05:00 · 4542 阅读 · 0 评论 -
排序算法----选择排序 冒泡排序
#include stdio.h>#include string.h>typedef int (*COMPAREFUNC)(void* p1, void *p2);typedef void (*SELECT)(void **a, int len);int compfunc(void *p1, void *p2);void select_sort(void **a, int len, CO原创 2007-10-26 17:30:00 · 675 阅读 · 0 评论 -
递归--全排列
#includestdio.h>void permulate(int *in, int *status, int *out, int pos)...{ int i=0; if (pos == 5) ...{ for (i=0;i5;i++) ...{ printf("%d ", out[i]); } printf原创 2007-11-25 18:30:00 · 654 阅读 · 0 评论 -
递归----组合
#include #include #include #define MAXBUFF 1024 #define N 4 void combine(char *dst, char *src, int pos, int start){ int i = 0; for (i = start; i dst[pos]=src[i]; dst[pos+1]=/0; printf("%s原创 2007-11-25 21:26:00 · 645 阅读 · 0 评论