打印二叉查找树所有满足k1

数据结构与算法分析——c语言描述 练习4.32 答案

程序会写复杂度还是不会算。。。

#include"fatal.h"
#include<stdlib.h>
#include"tree.h"
typedef int ElementType;

struct TreeNode;
typedef struct TreeNode *Position;
typedef struct TreeNode *SearchTree;

struct TreeNode {
	ElementType element;
	SearchTree left;
	SearchTree right;
};

void printElemBetwweenK1K2(SearchTree t, int k1, int k2) {
	if (t) {
		if (t->element >= k1)
			printElemBetwweenK1K2(t->left, k1, k2);
		if (t->element >= k1&&t->element <= k2)
			printf("%d ", t->element);
		if (t->element <= k2)
			printElemBetwweenK1K2(t->right, k1, k2);
		
	}
}

int main() {
	SearchTree t=NULL;

	for (int i = 0; i < 444; i++)
		t = insert(rand(), t);
	printElemBetwweenK1K2(t,400, 1500);
}

    原文作者:二叉查找树
    原文地址: https://blog.csdn.net/qq789045/article/details/51228757
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞