{
if(t == NULL) {
node * p;
p = (node *)malloc(sizeof(node));//其中(Node *)为强制转换,把返回类型void *转换为Node *,sizeof(Node)为获取Node类型占据空间的大小 p->data = key; p->LChild = NULL; p->RChild = NULL; t = p; } else {
if(key < t->data)
t->LChild = charu(LChild, key); else
t->RChild = charu(t->RChild, key); }
return t; //important! }
node * tree::jianlib(node *t)//建立玩家的树 {
int i,key;
for(i = 0; i < 5; i++) {
key = a.b[i]; t = charu(t, key); }
return t; }
node * tree::jianlic(node *t)//建立电脑的数 {
int i,key;
for(i = 0; i < 5; i++) {
key = a.c[i];
t = charu(t, key); }
return t;
}
void tree::paixu1(node * t) //中序遍历输出 {
if(t != NULL) {
paixu1(t->LChild); cout<< t->data<<\ paixu1(t->RChild); } }
void tree::paixu2(node * t,int *p) {
if( t == NULL) return; else {
paixu2(t->LChild,p); a.b[(*p)++] = t->data; paixu2(t->RChild,p); } }
void tree::paixu3(node * t,int *p) {
if( t == NULL) return; else {
paixu3(t->LChild,p); a.c[(*p)++] = t->data; paixu3(t->RChild,p); } }
int main() {int k =0;
srand((unsigned)time(NULL));//调用系统时间为随机函数赋初值 int n = 0;
while(k != -1) {
cout< cout<<\纸牌游戏****************\cout<<\ ******************************************\cout<<\游戏说明 ******** \cout<<\开始游戏********* \cout<<\开始出牌 ************* \cout<<\游戏结束 ********** \cout<<\ *************************************\cout<<\ 请输入(1、2、3、4) : \ cin>>k; switch(k) {case 1: a.yxsm(); break; case 2: {a.qk(); a.fp(); node * t1 = NULL; t1 = tr.jianlib(t1); tr.paixu1(t1);//中序遍历输出 node * t2 = NULL; t2 = tr.jianlic(t2); n = 0;//初始化 tr.paixu2(t1,&n); n = 0; tr.paixu3(t2,&n); cout< a.cp(); a.qk(); break; } case 4: k = -1; break; } } return 0; }