红黑树的创建+线索化+性质检验+笔画输入法
下面是源程序:[cpp]#include <stdio.h>#include <stdlib.h>#define TRUE 1#define FALSE 0#define HANZINUM 4762#define HANZILENGTH 4#define BIHUALENGTH 30char bihuaArr[HANZINUM][BIHUALENGTH];char hanziArr[HANZINUM][4];int first = 1;int num = 0;typedef struct bihuaData{char data[4];char bihua[30];}bihuaData;typedef int BOOL;typedef bihuaData ElemType;enum COLOR {Red, Black};enum pointerTag {Link, Thread};typedef struct RedBlackNode{ElemType data;struct RedBlackNode *left;struct RedBlackNode *right;struct RedBlackNode *p;char color;//Red, Blackchar ltag;char rtag;}RedBlackNode, *RedBlackTree;BOOL find(RedBlackTree root, const ElemType x);void pprint(RedBlackTree root, int i);void makeEmpty(RedBlackNode *t);void left_rotate(RedBlackTree *t, RedBlackNode *x);void right_rotate(RedBlackTree *t, RedBlackNode *x);void rb_insert(RedBlackTree *root, RedBlackNode *t);void rb_insert_fixup(RedBlackTree *root, RedBlackNode *z);int compare(RedBlackNode *y, RedBlackNode *z);void creat_rb_tree(RedBlackTree * root);BOOL check_rb_tree(RedBlackTree root);void check_black_num(RedBlackTree root, int n);void inorder_traverse_rb_tree(RedBlackTree root);void negative_inorder_traverse_rb_tree(RedBlackTree root);void inorder_threading_rb_tree(RedBlackTree *thrt, RedBlackTree root);int main(){RedBlackTree rbTree = NULL;creat_rb_tree(&rbTree);//check_rb_tree(rbTree);}void creat_rb_tree(RedBlackTree * root){FILE *fp = NULL;char *file = "./bihuabishun.txt";char *file3 = "./bihuahanzi.txt";int i;RedBlackNode *p = NULL;RedBlackTree thrt;freopen("data.out", "w", stdout);fp = fopen(file, "rb");if (fp == NULL){printf("exit!\n");exit(0);}fread(bihuaArr, BIHUALENGTH, HANZINUM, fp);fclose(fp);fp = fopen(file3, "rb");if (fp == NULL){printf("exit!\n");exit(0);}fread(hanziArr, 4, HANZINUM, fp);fclose(fp);for (i = 0 ; i < HANZINUM; i++){if (strcmp(bihuaArr[i], "") != 0 && strcmp(hanziArr[i], "") != 0){p = (RedBlackNode *)malloc(sizeof(RedBlackNode));if(p == NULL){printf("exit!\n");exit(0);}memset(p, 0, sizeof(RedBlackNode));strcpy(p->data.data, hanziArr[i]);strcpy(p->data.bihua, bihuaArr[i]);rb_insert(root, p);if(i == 4760){inorder_threading_rb_tree(&thrt, *root);negative_inorder_traverse_rb_tree(thrt);}}}}void left_rotate(RedBlackTree *t, RedBlackNode *x){RedBlackNode * y = NULL;y = x->right;x->right = y->left;if(y->left != NULL){y->left->p = x;}y->p = x->p;if(x->p == NULL){*t = y;}else if(x == x->p->left){x->p->left = y;}else{x->p->right = y;}y->left = x;x->p = y;}void right_rotate(RedBlackTree *t, RedBlackNode *x){RedBlackNode * y = NULL;y = x->left;x->left = y->right;if(y->right != NULL){y->right->p = x;}y->p = x->p;if(x->p == NULL){*t = y;}else if(x == x->p->left){x->p->left = y;}else{x->p->right = y;}y->right =补充:软件开发 , C++ ,
上一个:270B Multithreading
下一个:hdu 称乒乓球
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊