• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 5  文章 - 2  trackbacks - 0
            <2011年7月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            There can be no Triumph without Loss,No Victory without Suffering,No Freedom without Sacrifice. All you have to decide is what to do with the time that is given to you. Get busy Living, or Get busy Dying?

            常用鏈接

            留言簿

            隨筆分類(4)

            隨筆檔案(5)

            文章分類(88)

            文章檔案(10)

            Andriod

            Language

            OpenCV&OpenSSLink

            OpenSource

            Others

            Python&Ruby

            WP7

            WTL

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            //二叉樹的建立、存儲與遍歷
            #include <iostream.h>
            struct BintrNode
            {
            char value;
            BintrNode* lf;
            BintrNode* rt;
            };

            void init(BintrNode* &p)
            {
            char ch;
            cin>>ch;
            if(ch!='!')
            {
            p=new BintrNode;
            p->value=ch;
            init(p->lf);
            init(p->rt);
            }
            else
            {
            p=NULL;
            }
            }
            void pre(BintrNode* p)
            {
            if(p)
            {
            cout<<p->value;
            pre(p->lf);
            pre(p->rt);
            }
            }
            void ino(BintrNode* p)
            {
            if(p)
            {
            ino(p->lf);
            cout<<p->value;
            ino(p->rt);
            }
            }
            void pro(BintrNode* p)
            {
            if(p)
            {
            pro(p->lf);
            pro(p->rt);
            cout<<p->value;
            }
            }
            void main()
            {
            BintrNode* bt;
            init(bt);
            pre(bt);
            cout<<endl;
            ino(bt);
            cout<<endl;
            pro(bt);
            cout<<endl;

            }

            #include<stdio.h>
            #include<stdlib.h>
            struct node
            {
            int data;
            struct node *lh,*rh;
            int ltag,rtag;
            }*pr,*t,*s[30];

            struct node* creat()
            {
            struct node *t,*q;
            int i,x,j;
            printf("i,x=");
            scanf("%d%d",&i,&x);
            while((i!=0)&&(x!=0))
            {
            q=(struct node *)malloc(sizeof(struct node));
            q->data=x;
            q->lh=NULL;
            q->rh=NULL;
            s[i ]=q;
            if(i==1)
            t=q;
            else
            {
            j=i/2;
            if((i%2)==0)
            s[j]->lh=q;
            else
            s[j]->rh=q;
            }
            printf("i,x=");
            scanf("%d%d",&i,&x);
            }
            return(t);
            }

            /*void inthread(struct node *p) //遞歸算法
            {
            if(p!=NULL)
            {
            inthread(p->lh);
            printf("%6d\t",p->data);
            if(p->lh!=NULL)
            p->ltag=0;
            else
            {
            p->ltag=1;
            p->lh=pr;
            } //建立P節點的左線索,指向前趨節點PR
            if(pr!=NULL)
            {
            if(pr->rh!=NULL)
            pr->rtag=0;
            else
            {
            pr->rtag=1;
            pr->rh=p;
            }//前趨節點PR建立左線索,指向節點P
            }
            pr=p;//pr跟上p,以便p向后移動
            inthread(p->rh);
            }
            }*/

            void inthread(struct node *t)//非遞歸算法
            {
            int top,bools;
            struct node *p;
            pr=NULL;p=t;top=0;bools=1;
            do{
            while(p!=NULL)
            {
            top++;
            s[top]=p;
            p=p->lh;
            }
            if(top==0)bools=0;
            else
            {
            p=s[top];
            top--;
            printf("%6d",p->data);
            if(p->lh!=NULL)
            p->ltag=0;
            else
            {
            p->ltag=1;
            p->lh=pr;
            } //建立P節點的左線索,指向前趨節點PR
            if(pr!=NULL)
            {
            if(pr->rh!=NULL)
            pr->rtag=0;
            else
            {
            pr->rtag=1;
            pr->rh=p;
            }//前趨節點PR建立左線索,指向節點P
            }
            pr=p;//pr跟上p,以便p向后移動
            p=p->rh;
            }//END else
            }while(bools);
            pr->rh=NULL;
            }

            main()
            {
            pr=NULL;
            t=creat();
            inthread(t);
            pr->rh=NULL;
            }

            #include<stdio.h>
            #include<malloc.h>
            #include<iostream>

            //定義節點
            typedef struct BiNode{
            char data;
            struct BiNode *lch;
            struct BiNode *rch;
            }BiNode,*BiTree;

            //先序拓展序列建立二叉樹
            void Create(BiTree &T)
            {
            T =(BiNode*) malloc (sizeof(BiNode));

            printf("Enter the data \n");
            scanf(" %c",&T->data);
            if(T->data=='#') T = NULL;
            if(T){
            printf("");
            Create(T->lch);
            Create(T->rch);
            }
            }

            //先序遍歷 (遞歸)
            void Preorder (BiTree T)
            {
            if (T) {
            printf(" %c",T->data); // 訪問根結點

            Preorder(T->lch); // 遍歷左子樹
            Preorder(T->rch);// 遍歷右子樹
            }
            }

            //中序遍歷 (遞歸)
            void Inorder (BiTree T)
            {
            if(T) {
            Inorder(T->lch);

            printf(" %c",T->data);

            Inorder(T->rch);
            }
            }

            //后序遍歷 (遞歸)
            void Postorder (BiTree T)
            {
            if(T) {
            Postorder(T->lch);
            Postorder(T->rch);

            printf(" %c",T->data);
            }
            }

            int main()
            {
            //建樹
            printf("The fuction Create() is called.\n");
            BiTree T;
            Create(T);

            //三種遍歷遞歸算法
            printf("\n");
            printf("The fuction Preorder() is called.\n");
            Preorder(T);

            printf("\n");
            printf("The fuction Inorder() is called.\n");
            Inorder(T);

            printf("\n");
            printf("The fuction Postorder() is called.\n");
            Postorder(T);


            printf("\n");
            system("pause");

            }




            posted on 2010-12-06 11:03 jemmyLiu 閱讀(169) 評論(0)  編輯 收藏 引用 所屬分類: Arithmetic
            久久久久久国产精品免费无码| 国产色综合久久无码有码| 国产精品久久久久AV福利动漫| 久久婷婷五月综合国产尤物app| 奇米影视7777久久精品| 国产成人精品久久| 亚洲日本va午夜中文字幕久久| 久久人人爽人人人人爽AV| 91精品国产乱码久久久久久 | 精品国产99久久久久久麻豆| 久久久久国产精品熟女影院| 精品久久久久久国产免费了| 久久热这里只有精品在线观看| 99久久婷婷国产综合亚洲| 国产精品亚洲综合久久 | 久久精品国产精品亜洲毛片| 亚洲欧美一区二区三区久久| 97超级碰碰碰碰久久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 人妻精品久久久久中文字幕69| 久久久久人妻一区精品果冻| 国产精品一区二区久久精品| 亚洲AV无码久久寂寞少妇| 欧美久久亚洲精品| 亚洲国产成人久久精品影视| 欧美va久久久噜噜噜久久| 久久久亚洲欧洲日产国码是AV | 7777精品久久久大香线蕉 | 日本精品久久久久中文字幕8| 性高朝久久久久久久久久| 色成年激情久久综合| 久久Av无码精品人妻系列| 精品久久久无码21p发布| 亚洲国产综合久久天堂 | 综合久久一区二区三区 | 久久精品中文无码资源站| 午夜精品久久久久久影视riav| 欧美伊人久久大香线蕉综合69 | 亚洲国产精品无码久久SM| 97视频久久久| 久久亚洲精品无码观看不卡|