c++ 有序二叉树的应用

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

stricmp,strcmpi

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

用法:#include <string.h>

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

说明: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);
    }

    

}