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

            稀疏多項式的實現(xiàn)

             

            #include "stdafx.h"
            #include 
            <iostream>
            #include
            <list>
            #include
            <assert.h>
            using namespace std;

            class Term{ //代表多項式中的每一項
                friend ostream& operator<<(ostream&, Term&);
                friend istream
            & operator>>(istream&, Term&);
                friend 
            class Polynominal;
            public:
                Term(
            int c,int e) : coef(c), exp(e){}
                Term
            & operator+(Term&);
            private:
                
            int coef;
                
            int exp;
            };

            ostream
            & operator<<(ostream& out, Term& t){//輸出單項
                if(t.coef==0return out;
                
            else if(t.coef>0out<<"+";
                
            out<<t.coef<<"x^"<<t.exp;
                
            return out;
            }

            istream
            & operator>>(istream& in, Term& t){//輸入單項,包括指數(shù)和系數(shù)
                cout<<"Input coef & exp: "<<endl;
                
            in>>t.coef>>t.exp;
                
            return in;
            }

            Term
            & Term::operator +(Term& t){//項與項的加法    
                assert(exp==t.exp);
                Term
            * term=term=new Term(coef+t.coef, exp);
                
            return *term;
            }

            /********************************************************************
            *******************************************************************
            */

            class Polynominal{//多項式,用一個鏈表存儲
                friend istream& operator>>(istream&, Polynominal&);
                friend ostream
            & operator<<(ostream&, Polynominal&);
            public:
                Polynominal
            & operator+(Polynominal&);
            private:
                list
            <Term> pList;
            };

            istream
            & operator>>(istream& in, Polynominal& poly){//輸入Polynominal
                int n=0;
                cout
            <<"Input NUM of Term: "<<endl;
                cin
            >>n;
                cout
            <<"Input Every Term of The Polynominal: "<<endl;
                Term t(
            0,0);
                
            for(int i=0;i<n;i++){
                    cin
            >>t;
                    poly.pList.push_back(t);
                }
                
            return in;
            }

            template 
            <class T>
            ostream
            & operator<<(ostream& out, list<T>& myList){//重載實現(xiàn)對list的輸出
                list<T>::iterator iter;
                
            for(iter=myList.begin();iter!=myList.end();iter++)
                    cout
            <<*iter<<" ";
                cout
            <<endl;
                
            return out;
            }

            ostream
            & operator<<(ostream& out, Polynominal& poly){//輸出Polynominal
                out<<poly.pList;
                
            return out;
            }

            posted on 2008-10-23 18:44 deep2 閱讀(1484) 評論(2)  編輯 收藏 引用 所屬分類: 鏈表

            評論

            # re: 稀疏多項式的實現(xiàn) 2008-10-25 16:51 金山詞霸2008

            稀疏多項式一般用于什么場合呢?  回復  更多評論   

            # re: 稀疏多項式的實現(xiàn) 2008-10-25 17:14 deep2

            @金山詞霸2008
            比如:A = 3x^99 + 4x^999
            B = 2x^2 + 6x^99
            求 A+B  回復  更多評論   

            <2008年10月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統(tǒng)計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            一本伊大人香蕉久久网手机| 99久久精品国产一区二区| 国产精品一久久香蕉产线看| 久久九九全国免费| 色婷婷久久久SWAG精品| 久久夜色精品国产噜噜噜亚洲AV| 久久久人妻精品无码一区| 久久久久se色偷偷亚洲精品av| 久久精品国产99久久久香蕉| 国产激情久久久久久熟女老人| 久久人人爽人人爽人人片AV不 | 久久久久久精品免费看SSS| 国内精品综合久久久40p| 久久久久久狠狠丁香| 午夜福利91久久福利| 久久国产高清字幕中文| 精品久久久中文字幕人妻| 久久青草国产手机看片福利盒子 | 国产一区二区三区久久精品| 欧美性猛交xxxx免费看久久久| 亚洲性久久久影院| 99久久伊人精品综合观看| 国产精品久久久香蕉| 久久er国产精品免费观看8| 97久久天天综合色天天综合色hd| 国产精品永久久久久久久久久| 久久精品无码一区二区app| 国产精品久久国产精品99盘 | 亚洲国产成人乱码精品女人久久久不卡| 成人综合久久精品色婷婷| 久久国产成人亚洲精品影院| 77777亚洲午夜久久多喷| 久久中文骚妇内射| 亚洲AV无码久久精品蜜桃| 久久伊人五月丁香狠狠色| 亚洲精品tv久久久久久久久久| 久久成人国产精品| 久久久久免费精品国产| 66精品综合久久久久久久| 久久精品国产亚洲综合色| 色综合久久中文综合网|