diff --git "a/2017-1/Jasmine/exp05/\344\272\214\345\217\211\346\240\221.c" "b/2017-1/Jasmine/exp05/\344\272\214\345\217\211\346\240\221.c" new file mode 100644 index 00000000..b828cbf0 --- /dev/null +++ "b/2017-1/Jasmine/exp05/\344\272\214\345\217\211\346\240\221.c" @@ -0,0 +1,47 @@ +#include +#include +#define TelemType char +TelemType count = 0; +typedef struct BitNode +{ + TelemType data; + struct BitNode *lchild, *rchild; +}BitNode; +typedef enum +{ + error,ok +}Status; +BitNode* CreateBiTree(BitNode* T,TelemType *c) +{ + + if (c[count++] == ' ') + T = NULL; + else + { + T = (BitNode*)malloc(sizeof(BitNode)); + T->data = c[count-1]; + T->lchild=CreateBiTree(T->lchild,c); + T->rchild=CreateBiTree(T->rchild,c); + } + return T; +} +void PostOrder(BitNode* T) +{ + if (T!=NULL) + { + PostOrder(T->lchild); + PostOrder(T->rchild); + printf("%c ", T->data); + } +} +int main() +{ + BitNode* T=NULL; + char str[25] = "ABDG EH I K C F "; + TelemType *c = str; + printf("Create a BitTree:"); + T=CreateBiTree(T,c); + printf("%s\n", str); + printf("Postorder Traverse:"); + PostOrder(T); +} \ No newline at end of file diff --git "a/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\234.png" "b/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\234.png" new file mode 100644 index 00000000..601b8495 Binary files /dev/null and "b/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\234.png" differ diff --git "a/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\2342.png" "b/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\2342.png" new file mode 100644 index 00000000..d71ed28e Binary files /dev/null and "b/2017-1/Jasmine/exp05/\350\277\220\350\241\214\347\273\223\346\236\2342.png" differ diff --git a/2017-1/Jasmine/exp06/Bitree leaf.c b/2017-1/Jasmine/exp06/Bitree leaf.c new file mode 100644 index 00000000..7c31c267 --- /dev/null +++ b/2017-1/Jasmine/exp06/Bitree leaf.c @@ -0,0 +1,82 @@ +#include +#include +#define TelemType char +int count = 0; +int count1 = 0; +typedef struct BitNode +{ + TelemType data; + struct BitNode *lchild, *rchild; +}BitNode; +typedef enum +{ + error, ok +}Status; +BitNode* CreateBiTree(BitNode* T, TelemType *c) +{ + + if (c[count++] == ' ') + T = NULL; + else + { + T = (BitNode*)malloc(sizeof(BitNode)); + T->data = c[count - 1]; + T->lchild = CreateBiTree(T->lchild, c); + T->rchild = CreateBiTree(T->rchild, c); + } + return T; +} +void PostOrder(BitNode* T)//计算所有节点个数 +{ + if (T != NULL) + { + PostOrder(T->lchild); + PostOrder(T->rchild); + printf("%c ", T->data); + } +} +void Point(BitNode* T) +{ + if (T != NULL) + { + count1++; + Point(T->lchild); + Point(T->rchild); + } +} +int LeafPoint(BitNode* T)//返回叶子节点个数 +{ + int m, n; + if (T == NULL) + { + return 0; + } + if (T->lchild == NULL&&T->rchild == NULL) + { + return 1; + } + else + { + m = LeafPoint(T->lchild); + n = LeafPoint(T->rchild); + } + return m + n; +} +int main() +{ + BitNode* T = NULL; + int count2, count3; + char str[25] = "ABDG EH I K C F "; + TelemType *c = str; + printf("Create a BitTree:"); + T = CreateBiTree(T, c); + printf("%s\n", str); + printf("Postorder Traverse:"); + PostOrder(T); + Point(T); + printf("\nTotal Points:%d", count1); + count2=LeafPoint(T); + printf("\nLeaf Points:%d", count2); + count3 = count1 - count2; + printf("\nNot LeafPoints:%d", count3); +} \ No newline at end of file diff --git a/2017-1/Jasmine/exp06/Bitree more.c b/2017-1/Jasmine/exp06/Bitree more.c new file mode 100644 index 00000000..55b7e32b --- /dev/null +++ b/2017-1/Jasmine/exp06/Bitree more.c @@ -0,0 +1,101 @@ +#include +#include +#define TelemType char +int count = 0; +typedef struct BitNode +{ + TelemType data; + struct BitNode *lchild, *rchild; +}BitNode; +typedef enum +{ + error, ok +}Status; +BitNode* CreateBiTree(BitNode* T, TelemType *c) +{ + + if (c[count++] == ' ') + { + T = NULL; + } + else + { + T = (BitNode*)malloc(sizeof(BitNode)); + T->data = c[count - 1]; + T->lchild = CreateBiTree(T->lchild, c); + T->rchild = CreateBiTree(T->rchild, c); + } + return T; +} +void PostOrder(BitNode* T) +{ + if (T != NULL) + { + PostOrder(T->lchild); + PostOrder(T->rchild); + printf("%c ", T->data); + } +} +int Depth(BitNode* T) +{ + int depthL, depthR, depth; + if (!T) + { + depth = 0; + } + else + { + depthL = Depth(T->lchild); + depthR = Depth(T->rchild); + depth = 1 + (depthL > depthR ? depthL : depthR); + } + return depth; +} +int a[10] = { 0 }; +int i = 0; +void Width(BitNode *T) +{ + if (T != NULL) + { + if (i == 0) + { + a[0] = 1; + i++; + if (T->lchild != NULL) a[i]++; + if (T->rchild != NULL) a[i]++; + } + else { + i++; + if (T->lchild != NULL) a[i]++; + if (T->rchild != NULL) a[i]++; + } + Width(T->lchild); + i--; + Width(T->rchild); + } +} +int MaxWidth() +{ + int max = 0,i; + for (i = 0;i < 10;i++) //找出最大宽度 + if (max < a[i]) + max = a[i]; + return max; +} + +int main() +{ + BitNode* T = NULL; + char str[25] = "ABDG EH I K C F "; + TelemType *c = str; + printf("Create a BitTree:"); + T = CreateBiTree(T, c); + printf("%s\n", str); + printf("Postorder Traverse:"); + PostOrder(T); + printf("\nThe depth of the BiTree is:"); + printf("%d", Depth(T)); + printf("\nThe width of the BiTree is:"); + Width(T); + printf("%d", MaxWidth()); +} \ No newline at end of file diff --git "a/2017-1/Jasmine/exp06/\345\217\266\345\255\220\350\277\220\350\241\214\347\273\223\346\236\2342.png" "b/2017-1/Jasmine/exp06/\345\217\266\345\255\220\350\277\220\350\241\214\347\273\223\346\236\2342.png" new file mode 100644 index 00000000..c3b9b094 Binary files /dev/null and "b/2017-1/Jasmine/exp06/\345\217\266\345\255\220\350\277\220\350\241\214\347\273\223\346\236\2342.png" differ diff --git "a/2017-1/Jasmine/exp06/\350\277\220\350\241\214\347\273\223\346\236\234.png" "b/2017-1/Jasmine/exp06/\350\277\220\350\241\214\347\273\223\346\236\234.png" new file mode 100644 index 00000000..ef3f9d7b Binary files /dev/null and "b/2017-1/Jasmine/exp06/\350\277\220\350\241\214\347\273\223\346\236\234.png" differ