Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions 2017-1/Jasmine/exp05/二叉树.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<stdio.h>
#include<stdlib.h>
#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);
}
Binary file added 2017-1/Jasmine/exp05/运行结果.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2017-1/Jasmine/exp05/运行结果2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions 2017-1/Jasmine/exp06/Bitree leaf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include<stdio.h>
#include<stdlib.h>
#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);
}
101 changes: 101 additions & 0 deletions 2017-1/Jasmine/exp06/Bitree more.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include<stdio.h>
#include<stdlib.h>
#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());
}
Binary file added 2017-1/Jasmine/exp06/叶子运行结果2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2017-1/Jasmine/exp06/运行结果.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.