• java 计算器程序

    //版本:2.0.1 //作者:Linn //日期:2010.12.27 //说明:bug不较多,不爱弄了,先交作业再说,以后再改,有疑问请联系作者 //学习java,实验老师要求做的一个计算器,感觉自己写的还能让人接受吧,就发上来,大家都看看呗。用得着的就拿去

    0
    65
    17KB
    2010-12-30
    3
  • 排序二叉树程序,大学生可以用交作业

    #include<stdio.h> #include<malloc.h> struct tree { int num; struct tree *Lchild; struct tree *Rchild; }*head; struct tree *insert(struct tree **p0,int x) /*就改了这个参数,原因是一级指针不能返回申请的内存,因为参数副本问题*/ { struct tree *p1; /*建立一个排序二叉树*/ if(*p0==NULL) { p1=(struct tree *)malloc(sizeof(struct tree)); p1->num=x;p1->Lchild=NULL;p1->Rchild=NULL; *p0=p1; } else { if(x<(*p0)->num) { insert(&((*p0)->Lchild),x); } else if(x>(*p0)->num) { insert(&((*p0)->Rchild),x); } }return(head); } struct tree *DLR(struct tree *p0) /*先序遍历*/ { if(p0!=NULL) { printf("%3d",p0->num); DLR(p0->Lchild); DLR(p0->Rchild); }return NULL; } struct tree *LDR(struct tree *p0) /*中序遍历,也即是顺序输出*/ { if(p0!=NULL) { LDR(p0->Lchild); printf("%3d",p0->num); LDR(p0->Rchild); }return NULL; } struct tree *LRD(struct tree *p0) /*后序遍历*/ { if(p0!=NULL) { LRD(p0->Lchild); LRD(p0->Rchild); printf("%3d",p0->num); } } void main() { int i,x; head=NULL; for(i=1;i<=5;i++) { printf("please input the %d number:",i); /*不能输入相同数据,小bug*/ scanf("%d",&x); insert(&head,x); } printf("the preorder traversal is:");DLR(head);printf("\n"); printf("the inorder traversal is:");LDR(head);printf("\n"); printf("the postorder traversal is:");LRD(head);printf("\n"); getchar(); getchar(); }

    0
    56
    2KB
    2009-09-28
    9
关注 私信
上传资源赚积分or赚钱