急求C++课程设计!!!!!!

300行的C++课程设计...
实用能验证的.....
不要学生信息系统的````急用`````要有类!!!!!!!!!!

第1个回答  2007-07-07
只要是三百行就行不,你是这个意思?
给你一个树的!!不过是C的.不少了你就用着吧
#include <stdio.h>

#include <malloc.h>
#define null 0

typedef struct bitnode{
char date;
struct bitnode *lchild,*rchild;
}bitnode,*bittree;

typedef struct qnode
{bittree data;
struct qnode *next;
}qnode,*queueptr;

typedef struct
{queueptr front;
queueptr rear;
}linkqueue;

bitnode *creatbittree()
{bitnode *t;
char ch;
scanf("%c",&ch);
if(ch=='*')t=null;
else
{
t=(bitnode *)malloc(sizeof(bitnode));
t->date=ch;
t->lchild=creatbittree();
t->rchild=creatbittree();
}return t;
}
void preordertraverse(bitnode *t)
{if(t)
{printf("%c",t->date);
preordertraverse(t->lchild);
preordertraverse(t->rchild);}
else printf("*");
}

int treehigh(bitnode *t)
{int lh,rh,h;
if(t==null)
h=0;
else{
lh=treehigh(t->lchild);
rh=treehigh(t->rchild);
h=(lh>rh ? lh:rh)+1;
}
return h;
}

void exchange(bittree t)
{bittree p;
if(t!=null)
{p=t->lchild;
t->lchild=t->rchild;
t->rchild=p;
exchange(t->lchild);
exchange(t->rchild);
}
}

int initqueue(linkqueue *q)
{q->front=q->rear=(queueptr)malloc(sizeof(qnode));
if(q->front)return 1;
else return 0;
q->front->next=null;
}

void enqueue(linkqueue *q,bittree e)
{queueptr p;
p=(queueptr)malloc(sizeof(qnode));

p->data=e;
p->next=null;
q->rear->next=p;
q->rear=p;
}

int queueempty(linkqueue *q)
{if(q->front==q->rear)return 1;
else return 0;}

bittree dequeue(linkqueue *q)
{bittree e;
queueptr p;
if(q->front!=q->rear){
p=q->front->next;
e=p->data;
q->front->next=p->next;
if(q->rear==p)q->rear=q->front;
free(p);
return e;
}
}
void layerorder(bittree t)
{int i;
bittree p;
linkqueue *k;
k=(linkqueue *)malloc(sizeof(linkqueue));
initqueue(k);
enqueue(k,t);
while(!(i=queueempty(k)))
{p=dequeue(k);
printf("%c",p->data);
if(p->lchild)enqueue(k,p->lchild);
if(p->rchild)enqueue(k,p->rchild);
}
}

main()
{
bitnode *p;
int h;
p=null;
printf("\nplease enter the bittree nodes:");
p=creatbittree();
printf("root-lift-right output:");
preordertraverse(p);
h=treehigh(p);
printf("\ntree high :%d\n",h);
exchange(p);
printf("After exchang,root-lift-right output:");
preordertraverse(p);
printf("\nThe level output:");
layerorder(p);

}
相似回答