// 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;
}
Thứ Tư, 5 tháng 3, 2014
Đăng ký:
Đăng Nhận xét (Atom)
Bài đăng phổ biến
-
* lưu ý: tính năng này yêu cầu bạn phải có kết nối Internet khi sử dụng phần mềm. Bạn vui lòng thực hiện các bước sau để đăng ký dùng miễn p...
-
Công cụ Đăng Ký Bản Quyền Sử Dụng Kế Toán Smart Pro ( 2.0 - 2.5 - 3.0) Video Hướng Dẫn Đăng Ký Bản Quyền Kế Toán Smart Pro (2.0 - 2.5 - 3.0)...
-
HTsoft POS .NET là phần mềm quản lý Kho-Bán hàng và Chăm sóc khách hàng chuyên nghiệp, áp dụng tốt cho nhiều lĩnh vực kinh doanh khác nhau ...
-
Acc: architer Acc: fcyenluong Pass: 020901sl Acc: nhux12 Pass: phuongx1 Acc: vodoixxz Pass: 123456789y Acc: thanhkhunglk23 Pass: 01642688017...
-
Clover 3.0.386 - Tạo Tabs File Explorer cho Windows 8.1 http://www.softpedia.com/progDownload/Clover-EJIE-Download-220301.html
-
Đề bài: nhập 2 số nguyên dương a,b. Tính ước số chung lớn nhất và bội chung nhỏ nhất của a,b. Bài giải: Cách 1: #include <stdio.h> int...
-
#include <conio.h> #include <stdio.h> #define max 100 /*Hàm nhập ma trận hệ số*/ void NhapMaTran ( float A [ max ][ max ], in...
-
Đề bài: nhận vào một chuỗi các ký tự. Hãy đảo ngược các ký tự trong chuỗi. Bài giải: #include <string.h> #include <stdio.h> int...
-
Có thể xài được nhưng cũng có thể không xài được nếu như chủ nhân đã đổi pass. Acc: hoanglinh1714 Pass: A01656101024LINH Acc: hieukenpt19999...
-
Bổ sung vào các chức năng đã có ở hai phiên bản trước, phần mềm Quản lý gia phả phiên bản Advanced được nâng cấp thêm các tính năng nổi trội...

0 nhận xét:
Đăng nhận xét