⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 数据结构中区间树(红黑树的扩展出来的一种数据结构)的C语言实现。
💻 CPP
字号:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include"IntervalTree.h"
void main()
{
	time_t t;
	int A[5],i,temp;
	IntervalTNode B[5];
	pIntervalTNode pb,tRoot;
	tRoot=NULL;
	pb=B;
	
	srand((unsigned)time(&t));
	for(i = 0;i < 5;i++)
	{
		A[i] = rand() % 20;
	}
	for(i=0;i<5;i++)
	{
		B[i].low=A[i];
		B[i].high=A[i]+5;
		B[i].max=B[i].high;
		B[i].clr=red;
		B[i].lChild=NULL;
		B[i].parent=NULL;
		B[i].rChild=NULL;
	}
	printf("先将以下数据顺序插入到区间树中:\n");
	for(i = 0;i < 5;i++)
	{
		printf("%d:low=%d,high=%d,max=%d  ",i+1,B[i].low,B[i].high,B[i].max);
	}
	printf("\n");

	for(i=0;i<5;i++)
	{
		IntervalTInsert(&tRoot,pb);
		pb++;
	}
	//InorderIntTWalk(tRoot);
	//printf("\n");
	temp=rand()%20;
	printf("将搜寻以下区间:[%d,%d]",temp,temp+5);
	pb=IntervalSearch(tRoot,temp,temp+5);
	if(pb!=NULL)
		printf("找到重叠区间: x=[%d,%d]\n",pb->low,pb->high);
	else printf("没找到重叠区间\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -