The application of C + + ordered binary tree

Source: Internet
Author: User

Practice : Record student registration with ordered binary tree Time and name , and then to name Output Student Registration information in ascending order

Stricmp,strcmpi

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

Usage:#include <string.h>

Features: Compares strings S1 and S2, but does not differentiate between uppercase and lowercase letters.

Description:strcmpi is a macro definition to stricmp and does not actually provide this function.

When s1<s2 , the return value <0

When s1=s2 , the return value =0

When s1>s2 , the return value >0

I. Modification of CreateNodestructNode * CreateNode (Char*name)    {time_t T; TM*Timfo; structNode *p=malloc(sizeof(structnode)); P->pleft=p->pright=NULL; //Copy Namestrcpy (P->name,name);//Get the nameTime (&t); TIMFO= LocalTime (&t);//take current system timenode->stutime.hour=timfo->tm_hour;//whennode->stutime.min=timfo->tm_min;//pointsNode->Stuti Second, modify the AddNodestructNode * AddNode (structNode * Pnode,Char*v) {    //situation one pnode==null    if(pnode==NULL) {        returnCreateNode (v); }    //Pnode->data=v    if(stricmp (pnode->name,v) = =0)    {                returnPnode; }    //v more than node data    if(STRICMP (V,pnode->name) >0)    {        if(pnode->pright==NULL) {Pnode->pright=CreateNode (v); returnPnode->Pright; }Else returnAddNode (PNODE-&GT;PRIGHT,V);//Recursive invocation    }    //v less than node data    if(STRICMP (V,pnode->name) <0)    {        if(pnode->pleft==NULL) {Pnode->pleft=CreateNode (v); returnPnode->Pleft; }Else returnAddNode (PNODE-&GT;PLEFT,V);//Recursive invocation    }    returnNULL;} Third, modify the traversalvoidTraversal (structnode*Pnode) { inti; if(pnode->pleft!=NULL) {Traversal (Pnode-pleft); } printf ("%s,",pnode->name); if(pnode->pright!=NULL) {Traversal (Pnode-pright); }    }

The application of C + + ordered binary tree

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.