?? operationfamilytree.h
字號:
// OperationFamilytree.h: interface for the COperationFamilytree class.
//
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
////// 家譜操作類頭文件
////////////////////////////////////////////////////////////////////
#if !defined(AFX_OPERATIONPEDIGREE_H__E4F09334_6451_4AF0_8C1F_3EAB707AE2EF__INCLUDED_)
#define AFX_OPERATIONPEDIGREE_H__E4F09334_6451_4AF0_8C1F_3EAB707AE2EF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define MAX_CHARNUM 128
#define PEDIGREE_EMPTY -5
#define NOT_ENOUGH_MEMORY -4
#define READ_FILE_ERROR -3
#define WRITE_FILE_ERROR -2
#define FILE_DATA_ERROR -1
#define FILE_DATA_NOT_PRACTICAL 0
#define OK 1
struct Date{ //日期存儲結構
int year; //年
int month; //月
int day; //日
};
struct Info{ //一個人的有關信息存儲結構
char name[MAX_CHARNUM]; //姓名
Date birthday; //出生日期
int marry; //婚否
char addr[MAX_CHARNUM]; //住址
int live; //健在否
Date deathday; //死亡日期
};
typedef struct PersonNode{ //一個人的信息和與其他人關系的存儲結構
Info info; //自己的信息
PersonNode* parent; //指向父親的指針
PersonNode* child; //指向孩子的指針
PersonNode* sibling; //指向兄弟的指針
}*Person;
struct QuickSortNode{ //為以出生日期大小快速排序建立的存儲結構
Date birthday; //出生日期
Person oneself; //指向自己的指針
};
class COperationFamilytree
{
public:
COperationFamilytree();
virtual ~COperationFamilytree();
void NewFamilytree(); //新建一空家譜
int CreateFamilytree(CString filename); //從輸入文件filename中讀取數據建立家譜
void DestroyFamilytree(); //刪除家譜
int SaveFamilytree(CString filename); //保存家譜
void PreOrderTraverse(FILE* fp,Person& T //先序遍歷(為保存家譜而做)
,void (*Visit)(FILE* fp,Person& T));
void PostOrderTraverse(Person& T //后序遍歷(為刪除家譜而做)
,void (*Visit)(Person& T));
void Find(Person& T,Person& Tname,char* name);//從根結點出發,搜索name所在結點,如找到,存于Tname中,找不到,Tname為0
//使用前確保Tname指針為0
void Find(Person&T,Person*& Tname,int month,int day);//從根結點出發,搜索家譜中birthday.month等于month,birthday.day等于day的所有結點,
//如找到,存于以Tname為首地址的指針數組中,找不到,Tname為0使用前確保Tname指針為0
void Add(Person parent,Person addNode); //把addnode加為結點parent的孩子
void Delete(Person& rootNode); //刪除以rootNode為根結點的所有結點
void Modify(Person& pNode,Person newValue); //修改pNode結點為新值newValue
void SortByBirthday(QuickSortNode* order); //對家譜以出生日期排序,并把排序結果放在數組order中
void GetPersonNums(Person&T,int& personNums); //得到家譜中總人數
int InGenerationPos(Person pNode); //返回pNode在家譜中是第幾代
int InSiblingPos(Person pNode); //返回pNode在其兄弟中的排行
int ChildNums(Person pNode); //返回pNode孩子數
int CompareDate(Date date1,Date date2); //比較兩日期的大小
bool IsDateValid(Date date); //檢驗日期是否合法
Person& GetRoot(); //得到根結點
friend void SaveNode(FILE* fp,Person& pNode); //保存結點pNode到文件fp中
friend void DestroyNode(Person& pNode); //刪除結點
private:
Person T; //二叉樹的根結點
int ReadNode(FILE* fp,Person&T,char* parentname); //從文件fp中讀取信息到結點T中,讀取此結點的父親姓名到parentnaem中(供CreateFamilytree函數調用)
void InsertSibling(Person& firstSibling,Person insertSibling); //把insertSibling插入到以firstSibling為首的兄弟中(供CreateFamilytree函數調用)
void CopyInfoFromBiTreeToArray(Person&T,QuickSortNode*&order); //把家譜中以pNode結點為根結點的出生日期拷貝到快速排序結構數組order中(供SortByBirthday函數調用)
void QuickSort(QuickSortNode* order,int low,int high); //對order[low...high]中的記錄進行快速排序(供SortByBirthday函數調用)
int Partition(QuickSortNode* order,int low,int high); //對order[low..high]中的記錄進行一次排序(供QuickSort函數調用)
bool IsLeapYear(int year); //判斷是否閏年(供IsDateValid調用,以檢查日期是否合法)
};
#endif // !defined(AFX_OPERATIONPEDIGREE_H__E4F09334_6451_4AF0_8C1F_3EAB707AE2EF__INCLUDED_)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -