• <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
            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            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 閱讀(167) 評論(0)  編輯 收藏 引用 所屬分類: Arithmetic
            一级a性色生活片久久无| 国产午夜免费高清久久影院| 久久99精品久久久久久9蜜桃| 国产精品免费久久久久电影网| 久久精品无码一区二区三区日韩| 久久WWW免费人成—看片| 一个色综合久久| 久久大香香蕉国产| 久久精品成人免费国产片小草 | 国产亚洲综合久久系列| 久久久中文字幕| 久久久久国产成人精品亚洲午夜| 欧美日韩精品久久久免费观看| 国产精品久久久亚洲| 久久综合九色综合欧美就去吻| 国产成人无码精品久久久性色| 国产91久久综合| 人人狠狠综合久久88成人| 久久精品成人| 久久免费精品一区二区| 久久这里只有精品首页| 国内精品久久久久久久影视麻豆| 色8久久人人97超碰香蕉987| 久久毛片一区二区| 国产综合精品久久亚洲| 国内精品久久久久影院免费| 久久久午夜精品福利内容| 久久99精品国产麻豆蜜芽| 狠狠色丁香久久婷婷综| 久久国产精品77777| 亚洲国产精品18久久久久久| 亚洲精品无码专区久久同性男| 久久精品国产99久久丝袜| 久久久青草久久久青草| 久久青青草原精品影院| 久久综合久久综合九色| 久久久久久久99精品免费观看| 国产午夜免费高清久久影院| 国产精品久久毛片完整版| 久久国产精品无码HDAV| 色综合色天天久久婷婷基地|