• <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
            久久精品国产一区二区电影| 国内精品久久久久久久亚洲| 久久久久久久91精品免费观看| 国产精品久久久天天影视香蕉| 久久久精品国产| 亚洲中文字幕久久精品无码APP| 成人妇女免费播放久久久| 久久99国产综合精品| 91亚洲国产成人久久精品| 亚洲女久久久噜噜噜熟女| 久久黄视频| 国产美女亚洲精品久久久综合| 国产91色综合久久免费| 精品久久久中文字幕人妻| 久久久久一级精品亚洲国产成人综合AV区| 2021最新久久久视精品爱| 狠狠色丁香婷婷综合久久来来去 | 久久久久久曰本AV免费免费| 久久精品a亚洲国产v高清不卡| 一本久久知道综合久久| 四虎国产永久免费久久| 99久久无码一区人妻a黑| 中文字幕精品久久久久人妻| 狠狠精品久久久无码中文字幕| 亚洲AV无码久久寂寞少妇| 久久九九免费高清视频| 久久福利青草精品资源站| 国产精品免费福利久久| 久久国产欧美日韩精品| 人妻丰满?V无码久久不卡| 亚洲国产日韩欧美久久| 国产精品欧美久久久久无广告| 精品久久无码中文字幕| 久久男人Av资源网站无码软件| 伊人久久久AV老熟妇色| 久久久www免费人成精品| 久久se这里只有精品| 久久久精品波多野结衣| 亚洲精品无码久久毛片| 久久人做人爽一区二区三区| 亚洲中文字幕无码久久精品1|