zoukankan      html  css  js  c++  java
  • 实践6.1

    二叉排序树

    源程序:

    #include "stdio.h"
    #include "stdlib.h"

    typedef struct tnode
    {
    int id;
    int score;
    struct tnode *lchild,*rchild;
    }stu;
    void Ins_Student(stu **p,long id,int score)
    {
    stu *s;
    if(*p ==NULL)
    {
    s=(stu *)malloc(sizeof(stu));
    s->id=id;
    s->score=score;
    s->lchild=NULL;
    s->rchild=NULL;
    *p=s;
    }
    else if(score<( *p)->score)
    Ins_Student(&(( *p)->lchild),id,score);
    else
    Ins_Student(&(( *p)->rchild),id,score);
    }
    stu *Create_Student()
    {
    int id,score;
    stu *root;
    root=NULL;
    printf("请输入学号和成绩(用,隔开,用0结束:)");
    printf(" -------------------------------- ");
    printf("学号,成绩:");
    scanf("%ld,%d",&id,&score);
    while(score!=0)
    {
    Ins_Student(&root,id,score);
    printf("学号,成绩:");
    scanf("%ld,%d",&id,&score);
    }
    printf(" -------------------------------- ");
    return root;
    }
    void In_Order(stu *bt)
    {
    if(bt!=NULL)
    {
    In_Order(bt->lchild);
    printf("%ld,%d ",bt->id,bt->score);
    In_Order(bt->rchild);
    }
    }
    void main()
    {
    stu *root;
    root=Create_Student();
    printf("排序后的结果: ");
    printf("学号,成绩: ");
    In_Order(root);
    }

    运行结果:

  • 相关阅读:
    forward和redirect的区别
    转 jsp中 session的简单用法
    20_学生选课数据库SQL语句练习题1
    _学生选课数据库SQL语句练习题
    输入输出2
    接口提
    输入输出流3
    获取当前时间并显示在网页上
    简单的权限管理
    java关于时间
  • 原文地址:https://www.cnblogs.com/duanqibo/p/13329348.html
Copyright © 2011-2022 走看看