zoukankan      html  css  js  c++  java
  • c++ 有序二叉树的应用

    实作:以有序二叉树记录学生签到时间及名字,然后以名字升序输出学生签到信息

      stricmp,strcmpi 

      原型:extern int stricmp(char *s1,char * s2);        

      用法:#include <string.h>  

      功能:比较字符串s1s2,但不区分字母的大小写。  

      说明:strcmpi是到stricmp的宏定义,实际未提供此函数。

            当s1<s2时,返回值<0

            当s1=s2时,返回值=0

            当s1>s2时,返回值>0

    一、修改 CreateNode
    struct node * CreateNode(char *name)
    {
        time_t t;
        tm *timfo;
        struct node *p=malloc(sizeof(struct node));
        p->pLeft=p->pRight=NULL;
        //复制name
        strcpy(p->name,name); //获取名字
        
        time(&t);
        timfo= localtime(&t); //取当前系统时间
        node->stuTime.hour=timfo->tm_hour;//
        node->stuTime.min=timfo->tm_min;//
        node->stuTi
    二、修改 AddNode
      struct node * AddNode(struct node * pNode,char *v)
    {
        //情况一pNode==NULL
        if (pNode==NULL)
        {
            return CreateNode(v);
        }
        // pNode->data=v
        if (stricmp(pNode->name,v)==0)
        {
            
            return pNode;
        }
        //v大于结点数据
        if (stricmp(v,pNode->name)>0)
        {
            if (pNode->pRight==NULL)
            {
                pNode->pRight=CreateNode(v);
                return pNode->pRight;
            }else return AddNode(pNode->pRight,v); //递归调用
        }
        //v小于结点数据
        if (stricmp(v,pNode->name)<0)
        {
            if (pNode->pLeft==NULL)
            {
                pNode->pLeft=CreateNode(v);
                return pNode->pLeft;
            }else return AddNode(pNode->pLeft,v); //递归调用
        }
    
        return NULL;
    }
    三、修改 Traversal
      void traversal(struct node* pNode)
    { int i;
        if (pNode->pLeft!=NULL)
        {
            traversal(pNode->pLeft);
        }
         
            printf("%s,",pNode->name);
         
        if (pNode->pRight!=NULL)
        {
                traversal(pNode->pRight);
        }
    
        
    
    }
  • 相关阅读:
    方向ajax(http long request实现实时通信)
    HTTP防盗链与反防盗链
    linux开启过程详解
    自动化运维工具----saltstack安装及配置
    python----网络编程(TCP通讯)
    windows----bat方式实现ftp推送
    shell----ftp推送
    python----FTP文件拉取(new)
    haproxy----四层负载均衡
    python----时间转换
  • 原文地址:https://www.cnblogs.com/whzym111/p/6145714.html
Copyright © 2011-2022 走看看