• <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
            亚洲精品美女久久久久99| Xx性欧美肥妇精品久久久久久| 久久激情五月丁香伊人| 99久久免费国产精品| 久久99热这里只有精品国产| 久久久综合香蕉尹人综合网| 中文字幕无码久久精品青草| 久久国产精品一国产精品金尊| 久久国产亚洲精品麻豆| 亚洲中文字幕伊人久久无码| 国产精品久久一区二区三区| 一本久久精品一区二区| 精品国产乱码久久久久久郑州公司| 国产午夜电影久久| 亚洲人成伊人成综合网久久久| 国内精品久久久久久久久| 亚洲成色WWW久久网站| 久久久精品国产Sm最大网站| 国产麻豆精品久久一二三| 午夜精品久久久久久影视riav| 国产 亚洲 欧美 另类 久久| 久久久久亚洲Av无码专| 99久久免费国产精品特黄| 麻豆精品久久精品色综合| 人人狠狠综合久久88成人| 久久99国产精品久久99小说| 久久性精品| 久久九九免费高清视频| 欧美久久精品一级c片片| 久久午夜伦鲁片免费无码| 国产精品一区二区久久精品涩爱| 久久激情亚洲精品无码?V| 欧美伊香蕉久久综合类网站| 国产精品毛片久久久久久久| 精品久久久久久中文字幕人妻最新| 波多野结衣AV无码久久一区| 国内精品伊人久久久久777| 国产精品久久久久a影院| 久久久久久久精品妇女99| 亚洲AV无码成人网站久久精品大| 精品久久亚洲中文无码|