• <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
            国产精品久久久久久福利漫画 | 综合久久给合久久狠狠狠97色| 久久综合九色综合久99| 久久精品人人槡人妻人人玩AV| 久久婷婷国产综合精品| 久久精品国内一区二区三区| 人妻丰满?V无码久久不卡| 久久九九精品99国产精品| 久久se精品一区二区影院| 久久人人爽人人爽人人片av麻烦 | 亚洲国产精品嫩草影院久久| 国产美女亚洲精品久久久综合| 99久久er这里只有精品18| 色婷婷久久久SWAG精品| 久久精品国产久精国产思思| 久久综合成人网| 久久久久久狠狠丁香| 久久亚洲国产成人精品性色| 性做久久久久久久久久久| 99久久中文字幕| 亚洲午夜久久久久久久久久| 久久精品中文字幕有码| 99久久免费国产精精品| 日韩av无码久久精品免费| 国内精品久久久久久久久电影网| 国产精品综合久久第一页| 国产成人精品白浆久久69| 亚洲乱码中文字幕久久孕妇黑人| 久久综合色区| 97香蕉久久夜色精品国产 | 精品国产一区二区三区久久久狼 | 久久久久久久久久久久中文字幕| 亚洲欧美国产日韩综合久久| 国产免费久久精品99久久| 久久综合狠狠色综合伊人| 国产人久久人人人人爽| 精品国产乱码久久久久久1区2区 | 精品久久人妻av中文字幕| 亚洲精品tv久久久久久久久| 97精品依人久久久大香线蕉97| 亚洲人AV永久一区二区三区久久|