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

            稀疏多項式的實現

             

            #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){//輸入單項,包括指數和系數
                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){//重載實現對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 閱讀(1485) 評論(2)  編輯 收藏 引用 所屬分類: 鏈表

            評論

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

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

            # re: 稀疏多項式的實現 2008-10-25 17:14 deep2

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

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久综合伊人77777| 色欲久久久天天天综合网 | 日本久久久久久中文字幕| 国产精品久久影院| 亚洲精品高清国产一久久| 久久免费观看视频| 亚洲国产精品无码久久久秋霞2 | 伊人久久综合精品无码AV专区| 久久精品国产亚洲AV影院 | 国产一区二区精品久久凹凸 | 色欲久久久天天天综合网| 久久精品国产影库免费看 | 777米奇久久最新地址| 久久久久国产精品麻豆AR影院| 成人久久免费网站| 久久本道久久综合伊人| 久久精品国产清高在天天线| 久久久久人妻一区精品| 成人资源影音先锋久久资源网| 亚洲伊人久久成综合人影院| 久久精品国产亚洲av高清漫画| 久久精品中文字幕一区| 久久精品国产久精国产思思| 少妇被又大又粗又爽毛片久久黑人 | 国产精品久久久久a影院| 精品乱码久久久久久久| 性做久久久久久久久老女人| 777久久精品一区二区三区无码| 奇米影视7777久久精品| 亚洲va久久久久| 免费一级欧美大片久久网| a级毛片无码兔费真人久久| 久久精品人人做人人爽97 | 狠狠久久综合伊人不卡| 国产精品久久午夜夜伦鲁鲁| 亚洲国产精品无码久久| 一本一道久久综合狠狠老| 亚洲欧美久久久久9999 | 久久精品无码午夜福利理论片 | 久久综合久久综合九色| 国产成人久久精品区一区二区|