• <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>

            ADT多項式(C實現)

            初學數據結構,感覺還是應該多練習才好,于是寫了一個“ADT多項式”的實現,同時也當作一個學習,代碼如下,gcc編譯通過,由于寫的倉促,注釋較少,有什么問題可以給小弟留言。


            #include<stdio.h>
            #define MAX_TERMS 100


            typedef struct{
                float coef;        /*系數*/
                int expon;        /*指數*/
            } polynomial;

            polynomial terms[MAX_TERMS-1] = {2,1000,1,0,1,4,10,3,3,2,1,0},temp[MAX_TERMS];
            int avail = 0;


            void padd(int,int,int,int,int*,int*);
            void attach(float,int);
            int compare(int,int);


            int compare(int a,int b)
            {
                if(a > b)
                    return 1;
                else if(a == b)
                            return 0;
                        else
                            return -1;
            }


            void padd(int starta,int finisha,int startb,int finishb,int* startd,int* finishd)
            {
                float coefficient;
                *startd = avail;
                while(starta <= finisha && startb <= finishb)
                    switch(compare(terms[starta].expon,terms[startb].expon))
                    {
                        case -1 :
                                    attach(terms[startb].coef,terms[startb].expon);
                                    startb++;
                                    break;
                        case 0 :
                                    coefficient = terms[starta].coef + terms[startb].coef;
                                    if(coefficient)
                                        attach(coefficient,terms[starta].expon);
                                    starta++;
                                    startb++;
                                    break;
                        case 1 :
                                    attach(terms[starta].coef,terms[starta].expon);
                                    starta++;
                                    break;
                    }
                for( ; starta <= finisha; starta++)
                    attach(terms[starta].coef,terms[starta].expon);
                for( ; startb <= finishb; startb++)
                    attach(terms[startb].coef,terms[finishb].expon);
                *finishd = avail;
            }


            void attach(float coefficient,int exponent)
            {
                if(avail >= MAX_TERMS)
                {
                    printf("Too many terms in the polynomial");
                    return;
                }
                temp[avail].coef = coefficient;
                temp[avail].expon = exponent;
                avail++;
            }


            int  main()
            {
                int i,starta = 0,finisha = 1,startb = 2,finishb = 5,startd,finishd;
                padd(starta,finisha,startb,finishb,&startd,&finishd);
                printf("polynomial:\n");
                for(i = 0;i < finishd;++i)
                {
                    printf("coef %f  expon %d \n",temp[i].coef,temp[i].expon);
                }
                return 0;
            }


            posted on 2007-04-15 19:07 honker 閱讀(756) 評論(0)  編輯 收藏 引用

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            常用鏈接

            留言簿(3)

            隨筆分類(10)

            隨筆檔案(14)

            相冊

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            国产午夜精品久久久久九九| 国产精品伦理久久久久久| 亚洲精品NV久久久久久久久久| 亚洲а∨天堂久久精品| 精品久久久久久国产| 久久久久亚洲AV无码麻豆| 伊人久久精品线影院| 亚洲精品无码专区久久同性男| 国产毛片欧美毛片久久久| 99国产精品久久久久久久成人热| 久久天堂电影网| 久久久久久久97| 久久精品不卡| 久久亚洲国产中v天仙www| 亚洲精品99久久久久中文字幕 | 久久国产热这里只有精品| 亚洲中文精品久久久久久不卡| 成人精品一区二区久久| 亚洲精品乱码久久久久久按摩 | 久久久久国产视频电影| 久久精品aⅴ无码中文字字幕重口| 久久青青国产| 伊人色综合久久天天| 久久亚洲精品国产精品| 亚洲午夜久久久| 亚洲人成无码www久久久| 久久精品一区二区| 精品久久久久久久| 久久精品亚洲中文字幕无码麻豆| 99久久精品国产一区二区| 香蕉久久影院| 久久久亚洲精品蜜桃臀| 精品久久久久久无码中文字幕| 秋霞久久国产精品电影院| 97久久天天综合色天天综合色hd| 久久无码高潮喷水| 久久国产欧美日韩精品| 精品多毛少妇人妻AV免费久久| 伊人久久国产免费观看视频| 亚洲国产天堂久久久久久| 人妻无码精品久久亚瑟影视|