• <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àng)式的實(shí)現(xiàn)

             

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

            class Term{ //代表多項(xiàng)式中的每一項(xiàng)
                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){//輸出單項(xiàng)
                if(t.coef==0return out;
                
            else if(t.coef>0out<<"+";
                
            out<<t.coef<<"x^"<<t.exp;
                
            return out;
            }

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

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

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

            class Polynominal{//多項(xiàng)式,用一個(gè)鏈表存儲(chǔ)
                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){//重載實(shí)現(xiàn)對(duì)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) 評(píng)論(2)  編輯 收藏 引用 所屬分類: 鏈表

            評(píng)論

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

            稀疏多項(xiàng)式一般用于什么場(chǎng)合呢?  回復(fù)  更多評(píng)論   

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

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

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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲成色WWW久久网站| 无码伊人66久久大杳蕉网站谷歌 | 国产成人无码精品久久久久免费 | 99国产欧美精品久久久蜜芽| 精品久久久久久无码专区| 91精品国产综合久久香蕉| 亚洲国产小视频精品久久久三级| 久久无码国产专区精品| 九九99精品久久久久久| 久久精品中文字幕大胸| 色综合色天天久久婷婷基地| 国产精品99久久久精品无码| 久久国产精品成人免费 | 久久99精品久久久久久不卡| 亚洲色大成网站WWW久久九九| 99热精品久久只有精品| 久久人爽人人爽人人片AV| 久久99热只有频精品8| AA级片免费看视频久久| 青草国产精品久久久久久| 无码精品久久一区二区三区 | 99久久精品免费看国产一区二区三区 | 亚洲色欲久久久久综合网| 国产精品岛国久久久久| 人人狠狠综合久久88成人| 久久久久国色AV免费看图片 | 狼狼综合久久久久综合网| 久久综合色老色| 色偷偷91久久综合噜噜噜噜| 日韩精品久久无码中文字幕| 伊人精品久久久久7777| 精品久久人人爽天天玩人人妻 | 国内精品久久久久久中文字幕 | 18禁黄久久久AAA片| 亚洲精品综合久久| 热久久最新网站获取| 色播久久人人爽人人爽人人片aV| 精品久久人人妻人人做精品| 久久er国产精品免费观看8| 久久99精品国产麻豆不卡| 国产三级精品久久|