• <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 閱讀(1489) 評(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年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久久久久久国产免费看| 国产精品久久久久蜜芽| 久久久国产打桩机| 久久人人爽爽爽人久久久| 国产精品久久久久久福利漫画 | 国产精品gz久久久| 久久涩综合| 久久成人精品视频| 亚洲愉拍99热成人精品热久久| 一本久久a久久精品综合夜夜| 婷婷久久综合| 国产成人精品久久亚洲高清不卡| 亚洲欧美成人久久综合中文网 | 九九热久久免费视频| 久久亚洲AV成人无码电影| 久久无码av三级| 2021久久精品国产99国产精品| 成人a毛片久久免费播放| 久久人人爽人人爽人人片AV东京热| 狠狠色丁香久久综合五月| 久久精品综合网| 久久综合精品国产一区二区三区| 久久亚洲私人国产精品| 国产精品久久久久久五月尺| 99久久亚洲综合精品网站| 久久青青草原亚洲av无码app| 国产69精品久久久久9999APGF| 久久99精品久久久久久齐齐| 久久99国产亚洲高清观看首页 | 久久精品国产精品青草| 人妻无码αv中文字幕久久琪琪布| 久久亚洲高清综合| 久久久久久一区国产精品| 久久久久免费精品国产| 国内精品久久国产大陆| 99久久中文字幕| 久久se精品一区二区| 国产精品久久久久久一区二区三区 | 一级女性全黄久久生活片免费| 久久人人爽人人爽人人片AV麻豆| 国产日韩久久免费影院|