亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? trees.cpp

?? 對三種數據結構的分析.avl tree,splaytree和binary search tree的插入和刪除的算法復雜度分析.
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef struct TreeNode *searchtree;
typedef struct AvlNode *avltree;
typedef struct TreeNode *splaytree;

clock_t  start, stop; /* clock_t is a built-in type for processor time (ticks) */
double  duration;  /* records the run time (seconds) of a function */

/* functions about binary search tree */
searchtree S_Insert(int element,searchtree T); /*insert the integers in the binary search tree*/
searchtree S_Delete(int element,searchtree T); /* delete the integers from the binary search tree*/
searchtree S_FindMin(searchtree T); /* find the minimum in the binary search tree */
searchtree MakeEmpty(searchtree T); /* make the tree empty */
/* functions about avl tree */
int Height(avltree T); /* calculate the avltree's height */
int Max(int a,int b); /* find the larger one */
avltree A_FindMin(avltree T);  /* find the minimum in the AVL tree */
avltree A_Insert(int element,avltree T);  /*insert the integers in the AVL tree*/
avltree A_Delete(int element,avltree T);  /* delete the integers from the AVL tree*/
avltree A_SingleRotateWithLeft(avltree T); /* LL rotate */
avltree A_SingleRotateWithRight(avltree T); /* RR rotate */
avltree A_DoubleRotateWithLeft(avltree T); /* LR rotate */
avltree A_DoubleRotateWithRight(avltree T); /* RL rotate */
avltree Makeempty(avltree T);
/* functions about splay tree */
splaytree splay(int element,splaytree T); /* splay at the node element */
splaytree FindMax(splaytree T); /* find the maxmum in the splay tree */
splaytree Sp_Insert(int element,splaytree T); /* insert the integers in the splay tree */
splaytree Sp_Delete(int element,splaytree T); /* delete the integers from the splay tree*/
splaytree Sp_SingleRotateWithLeft(splaytree T); /* lefe rotate */
splaytree Sp_SingleRotateWithRight(splaytree T); /* right rotate */
splaytree Sp_DoubleRotateWithLeft(splaytree T); /* LR rotate */
splaytree Sp_DoubleRotateWithRight(splaytree T); /* RL rotate */


struct TreeNode  /* binary search tree's node T1 & splay tree's node T3 */
{
	int Element;
	searchtree Left;
	searchtree Right;
}*T1,*T3;
struct AvlNode  /* AVL tree's node T2*/
{
	int Element;
	avltree Left;
	avltree Right;
	int height;
}*T2;

/**************************************************************************************************
************************************** end of declaration ******************************************
***************************************************************************************************/

int main ( )
{


	int N1,N2; /* N1 is the total integers to insert and N2 is the total integers to delete*/
	int num; /* num is the number from input */
	int i;
	FILE *ins,*del,*out;

	if((out=fopen("output.txt","w"))==NULL) /* open the output.txt to show the insert&delete time */
	{
		printf("Can't open the input.txt");
		exit(0);
	}

/*************************************************************************************************
*********************************** BINATY SEARCH TREE *******************************************
**************************************************************************************************/

	if((ins=fopen("ins.txt","r"))==NULL)  /* read ins.txt including n integers to insert */
	{
		printf("Can't open the ins.txt");
		exit(0);
	}
       	
		if((del=fopen("del.txt","r"))==NULL)  /* read del.txt including n integers to delete */
	{
		printf("Can't open the del.txt");
		exit(0);
	}

	fscanf(ins,"%d",&N1); /*read the total number to insert */
	fscanf(del,"%d",&N2); /*read the total number to delete */

	if(N1==0 || N2 ==0)
	{
		printf("illegal input");
		exit(0);
	}

	T1=MakeEmpty(T1);
	start = clock(); 	/* INSERTION*/
	for(i=0;i<N1;i++)
	{
		fscanf(ins,"%d",&num);/*read esch number*/
		T1=S_Insert(num,T1); /*insert the integers*/
    }
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Inserting time of Binary Search Tree is %le\n",duration);

	start = clock(); 	/* DELETION */
	for(i=0;i<N2;i++)
	{
		fscanf(del,"%d",&num); /* read esch number */
		T1=S_Delete(num,T1); /* delete the integers */
	}
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Deleting time of Binary Search Tree is %le\n",duration);

	free(T1);

	fclose(ins); /* close the ins.txt */
	fclose(del); /* close the del.txt */

/**************************************************************************************************
******************************************* AVL TREE **********************************************
***************************************************************************************************/

	if((ins=fopen("ins.txt","r"))==NULL)  /* read ins.txt including n integers to insert */
	{
		printf("Can't open the ins.txt");
		exit(0);
	}
       if((del=fopen("del.txt","r"))==NULL)  /* read del.txt including n integers to delete */
	{
		printf("Can't open the del.txt");
		exit(0);
	}

	fscanf(ins,"%d",&N1); /*read the total number to insert */
	fscanf(del,"%d",&N2); /*read the total number to delete */
    T2=Makeempty(T2);
	start = clock(); 	/* INSERTION*/
	for(i=0;i<N1;i++)
	{
		fscanf(ins,"%d",&num);/*read esch number*/
		T2=A_Insert(num,T2); /*insert the integers*/
	}
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Inserting time of AVL Tree is %le\n",duration);

	start = clock(); 	/* DELETION */
	for(i=0;i<N2;i++)
	{
		fscanf(del,"%d",&num);/* read esch number */
		T2=A_Delete(num,T2); /* delete the integers */
	}
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Deleting time of AVL Tree is %le\n",duration);

	free(T2);

	fclose(ins); /* close the ins.txt */
	fclose(del); /* close the del.txt */

/**************************************************************************************************
******************************************* splay TREE ********************************************
**************************************************************************************************/

	if((ins=fopen("ins.txt","r"))==NULL)  /* read ins.txt including n integers to insert */
	{
		printf("Can't open the ins.txt");
		exit(0);
	}
       if((del=fopen("del.txt","r"))==NULL)  /* read del.txt including n integers to delete */
	{
		printf("Can't open the del.txt");
		exit(0);
	}

	fscanf(ins,"%d",&N1); /*read the total number to insert */
	fscanf(del,"%d",&N2); /*read the total number to delete */

	T3=MakeEmpty(T3);
    start = clock(); 	/* INSERTION*/
	for(i=0;i<N1;i++)
	{
		fscanf(ins,"%d",&num);/*read esch number*/
		T3=Sp_Insert(num,T3); /*insert the integers*/
	}
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Inserting time of Splay Tree is %le\n",duration);

	start = clock(); 	/* DELETION */
	for(i=0;i<N2;i++)
	{
		fscanf(del,"%d",&num);/* read esch number */
		T3=Sp_Delete(num,T3); /* delete the integers */
	}
	stop = clock();	/* records the ticks at the end of the function call */
	duration = ((double)(stop - start))/CLK_TCK; /* CLK_TCK is a built-in constant = ticks per second */
	fprintf(out,"Deleting time of Splay Tree is %le\n",duration);

	free(T3);

	fclose(ins); /* close the ins.txt */
	fclose(del); /* close the del.txt */

return 1;
}

/**************************************************************************************************
*********************************** functions about binary searchtree *****************************/

searchtree MakeEmpty(searchtree T)  /* make the tree empty */
{
	if(T!=NULL)
	{
		MakeEmpty(T->Left);
		MakeEmpty(T->Right);
		free(T);
	}
	return NULL;
}

searchtree S_Insert(int element,searchtree T) /*insert the integers*/
{
	if(T==NULL) /*create and return a one-node tree*/
	{
		T=(searchtree)malloc(sizeof(struct TreeNode));
		if(T==NULL)  /*fatal error*/
		{
			printf("out of space");
			exit(0);
		}
		else /* create the new node */
		{
			T->Element=element;
			T->Left=T->Right=NULL;
		}
	}
	else if(element < T->Element) /*element is smaller than the T->Element */
		T->Left=S_Insert(element,T->Left); /*go to the left subtree*/
	else if(element > T->Element) /*element is larger than the T->Element */
		T->Right=S_Insert(element,T->Right); /*go to the right subtree*/

	return T;
}

searchtree S_Delete(int element,searchtree T) /* delete the integers */
{
	searchtree TmpCell;

	if(T==NULL) /* empty tree */
		printf("Not found\n");
	else if(element < T->Element) /* go to the left subtree */
		T->Left=S_Delete(element,T->Left);
	else if(element > T->Element)  /* go to the right subtree */
		T->Right=S_Delete(element,T->Right);
	else /* find the element to be deleted */
		if(T->Left && T->Right) /*two children */
		{
			/* replace with the smallest in the right subtree */
			TmpCell=S_FindMin(T->Right);
			T->Element=TmpCell->Element;
			T->Right=S_Delete(T->Element,T->Right);
		}
		else /* one or zero child */
		{
			TmpCell=T;
			if(T->Left==NULL) /* has right child or zero child */
				T=T->Right;
			else if(T->Right==NULL) /* zero child */
				T=T->Left;
			free(TmpCell); /* free the space of TmpCell */
		}

	return T;
}

searchtree S_FindMin(searchtree T) /* find the minimum in the tree*/
{
	if(T!=NULL)
		while(T->Left!=NULL)
			T=T->Left;

	return T;
}

/************************************ functions about Avltree **************************************/

 avltree Makeempty(avltree T)  /* make the tree empty */
{
	if(T!=NULL)
	{
		Makeempty(T->Left);
		Makeempty(T->Right);
		T->height=-1;
		free(T);
	}
	return NULL;
}
avltree A_Insert(int element,avltree T)  /*insert the integers*/
{
	if(T==NULL) /*create and return a one-node tree*/
	{
		T=(avltree)malloc(sizeof(struct AvlNode));
		if(T==NULL) /*fatal error*/
		{
			printf("out of space");
			exit(0);
		}
		else /* create the new node */
		{
			T->Element=element;
			T->height=0;
			T->Left=T->Right=NULL;
		}
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩免费高清一区色橹橹| 国产成人免费在线观看不卡| 精品国产凹凸成av人网站| 不卡一二三区首页| 天天影视网天天综合色在线播放| 国产欧美日韩麻豆91| 欧美午夜电影在线播放| 成人免费视频播放| 老司机免费视频一区二区| 亚洲激情第一区| 国产日韩三级在线| 精品久久人人做人人爽| 欧美精品18+| 91麻豆国产精品久久| 国产成人免费在线观看不卡| 久久99久久99小草精品免视看| 一区二区三区高清在线| 国产精品久久久久久一区二区三区| 日韩精品一区二区三区三区免费| 在线免费亚洲电影| 99re成人在线| 成人激情动漫在线观看| 国产一区二区三区四区五区美女| 全国精品久久少妇| 丝袜美腿一区二区三区| 一区二区三区四区精品在线视频| 国产精品久久久久天堂| 欧美国产激情二区三区| 久久免费美女视频| 精品国产乱码久久久久久久 | 捆绑调教美女网站视频一区| 夜夜嗨av一区二区三区四季av| 国产精品初高中害羞小美女文| 久久青草国产手机看片福利盒子 | 欧美一卡二卡三卡| 欧美老女人第四色| 欧美日韩电影在线播放| 欧美视频一区在线观看| 欧美三电影在线| 欧美撒尿777hd撒尿| 欧美色图片你懂的| 欧美亚洲国产一区二区三区va| 一本高清dvd不卡在线观看| 91蜜桃婷婷狠狠久久综合9色| 99久久99久久综合| 日本国产一区二区| 欧美吻胸吃奶大尺度电影 | 欧洲国内综合视频| 欧美性猛交xxxxxx富婆| 欧美男人的天堂一二区| 制服丝袜在线91| 精品免费99久久| 久久久久久久久久久99999| 国产人成一区二区三区影院| 久久精品欧美日韩精品| 国产精品国产三级国产aⅴ入口 | 成人免费毛片片v| 97久久精品人人做人人爽| 91免费国产在线| 欧美三级韩国三级日本三斤| 日韩亚洲欧美中文三级| 久久精品男人天堂av| 国产精品国产三级国产普通话三级 | 日韩av二区在线播放| 久草这里只有精品视频| 风间由美中文字幕在线看视频国产欧美| 国产·精品毛片| 在线免费观看一区| 日韩欧美国产综合一区| 国产欧美一区二区在线| 伊人色综合久久天天人手人婷| 婷婷开心激情综合| 国产乱码精品一区二区三区av | 日韩电影在线一区二区三区| 国产剧情一区二区| 色吧成人激情小说| 91精品国产91综合久久蜜臀| 国产欧美在线观看一区| 亚洲综合色网站| 久久99久久99精品免视看婷婷| jizz一区二区| 欧美一二三四在线| 国产精品国产馆在线真实露脸 | 色美美综合视频| 欧美一区二区三区四区久久| 中文字幕不卡在线播放| 午夜激情久久久| 国产黄色精品网站| 欧美日高清视频| 国产精品国产三级国产普通话三级| 日日嗨av一区二区三区四区| 成人av影院在线| 日韩欧美黄色影院| 亚洲国产日韩a在线播放| 国产寡妇亲子伦一区二区| 欧美日韩亚洲综合在线| 欧美国产精品v| 免费看黄色91| 欧美丝袜丝nylons| 亚洲色图自拍偷拍美腿丝袜制服诱惑麻豆| 日韩影院在线观看| 日本高清视频一区二区| 国产日韩亚洲欧美综合| 免费成人结看片| 欧美视频日韩视频在线观看| 国产精品女主播av| 国产在线视频一区二区| 欧美高清hd18日本| 亚洲欧美激情视频在线观看一区二区三区 | 欧美精品一二三区| 一区视频在线播放| 国产精品18久久久| 日韩你懂的在线播放| 香蕉影视欧美成人| 91久久精品一区二区三| 国产精品久久久久影院色老大| 久久国产精品免费| 欧美一区二区三区公司| 亚洲成人激情综合网| 色综合天天综合网国产成人综合天| 国产清纯美女被跳蛋高潮一区二区久久w | 欧美视频第二页| 亚洲欧美日韩国产综合| 成人av一区二区三区| 国产精品欧美一区二区三区| 国产精品123| 久久精品这里都是精品| 黄色资源网久久资源365| 欧美一区二区免费视频| 午夜精品一区在线观看| 欧美日韩一区小说| 亚洲国产精品久久艾草纯爱 | 久久女同精品一区二区| 狠狠色丁香久久婷婷综| 精品国产3级a| 黄一区二区三区| 国产欧美日韩在线| 国产69精品久久久久毛片| 国产精品久久久久一区二区三区| 成人三级在线视频| 中文字幕一区视频| 色综合天天做天天爱| 亚洲午夜久久久久久久久电影院 | 日韩成人一区二区三区在线观看| 欧美日韩国产综合一区二区 | 韩国成人在线视频| 久久久久久亚洲综合| 国产98色在线|日韩| 中文字幕不卡一区| 色噜噜狠狠成人网p站| 亚洲成人综合视频| 日韩一区二区精品在线观看| 久久成人久久爱| 国产免费久久精品| 91在线观看一区二区| 一区二区不卡在线视频 午夜欧美不卡在| 在线一区二区三区做爰视频网站| 亚洲香蕉伊在人在线观| 91精品国产乱码久久蜜臀| 精品午夜久久福利影院 | 亚洲黄色免费电影| 欧美二区乱c少妇| 国产一区二区三区四| 亚洲精品视频在线| 制服丝袜av成人在线看| 国产一区亚洲一区| 亚洲欧美偷拍卡通变态| 欧美日韩国产大片| 九一九一国产精品| 亚洲日本乱码在线观看| 欧美一区二区三区公司| 成人18视频在线播放| 午夜av一区二区三区| 国产亚洲欧美日韩日本| 欧美亚洲一区二区在线| 精品一区二区三区视频| 《视频一区视频二区| 91精品欧美久久久久久动漫| 成人综合在线观看| 日韩在线一二三区| 国产精品毛片大码女人| 欧美日韩大陆一区二区| 国产成人av一区二区三区在线 | 欧美精品一二三区| 成人中文字幕合集| 日日欢夜夜爽一区| **欧美大码日韩| 精品美女被调教视频大全网站| 91亚洲精品乱码久久久久久蜜桃| 美女一区二区三区在线观看| 成人免费小视频| 久久综合国产精品| 欧美色图片你懂的| 91在线视频播放地址| 国产曰批免费观看久久久| 亚洲第一在线综合网站| 日韩一区日韩二区| 精品处破学生在线二十三| 欧美色图激情小说| 色婷婷综合视频在线观看|