kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Tư, 5 tháng 3, 2014

// Ho va ten
// Lop:

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define NIL -1
#define MaxLength 11

typedef
char DataType;
typedef
int Node;
typedef struct
Tree{
DataType Data[MaxLength];
Node Parent[MaxLength];
int
MaxNode; // so nut hien co trong cay
};

void
MakeNullTree(Tree &T){
T.MaxNode = 0;
}

int
EmptyTree(Tree T){
return
(T.MaxNode == 0);
}

Node Parent(Node n, Tree T){
return
T.Parent[n];
}

Node LeftMostChild(Node n, Tree T){
for
(int i=n+1 ; i<T.MaxNode;i++ )
if
(T.Parent[i] == n)
return
i;
return
NIL;
}

Node RightSibling(Node n,Tree T){
Node p = Parent (n,T);
for
(Node i=n+1;i<T.MaxNode;i++)
if
(p == Parent(i,T))
return
i;
return
NIL;
}

DataType Label(Node n, Tree T){
return
T.Data[n];
}

void
PreOrder(Node n, Tree T){
printf("%c ",Label(n,T));
Node i = LeftMostChild(n,T);
while
(i!=NIL){
PreOrder(i,T);
i = RightSibling(i,T);
}
}

void
PostOrder(Node n, Tree T){
Node i = LeftMostChild(n,T);
while
(i!=NIL){
PostOrder(i,T);
i = RightSibling(i,T);
}

printf("%c ",Label(n,T));
}


void
InOrder(Node n, Tree T){
Node i = LeftMostChild(n,T);
if
(i!=NIL)
InOrder(i,T);
printf("%c ",Label(n,T));
i = RightSibling(i,T);
while
(i!=NIL){
InOrder(i,T);
i = RightSibling(i,T);
}
}


Node Root(Tree T){
return
0;
}


int
main(){
Tree T;
MakeNullTree(T);
// printf("Root = %d",Root(T));
// T.MaxNode = 10;
// T.Data={'A','B','C','D','E','F','G','H','I','J'};
// T.Parent={-1, 0, 0 ,1,1,4,4,4,2,2 };
printf("Cay co may nut ? ");
scanf("%d",&T.MaxNode);
fflush(stdin);
printf("Data[0] = ");
scanf("%c",&T.Data[0]);
T.Parent[0]=-1;
for
(int i=1;i<T.MaxNode;i++){
fflush(stdin);
printf("Data[%d] = ",i);
scanf("%c",&T.Data[i]);
printf("Parent[%d] = ",i);
scanf("%d",&T.Parent[i]);
}


printf("\nTien tu:");
PreOrder(0,T);
printf("\nTrung tu: ");
InOrder(0,T);
printf("\nHau tu: ");
PostOrder(0,T);
printf("\n\n--------\n\n");
printf("So Luong Nut = %d \n",T.MaxNode);
printf("Cay Rong Khong? %d\n",EmptyTree(T));
printf("Cha(%c) = %c\n",Label(7,T),Label(Parent(7,T),T));
printf("Con Trai(%c) = %c\n",Label(2,T),Label(LeftMostChild(2,T),T));
printf("Anh Em Phai(%c) = %c\n",Label(5,T),Label(RightSibling(5,T),T));

return
0;
}
05 Mar 2014

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Bài đăng phổ biến