廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 7933 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
benjaminchch 手機
個人文章 個人相簿 個人日記 個人地圖
初露鋒芒
級別: 初露鋒芒 該用戶目前不上站
推文 x0 鮮花 x7
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
文章表情[C/C++][範例] 多項式相加(Link List版)
這程式邏輯不難....難在如果你需要由使用者輸入那就麻煩。

我不喜歡做輸入的設計,浪費我的時間.....我只把相加的重點及結構設計做出來。


#include

using namespace std;


//多項式結構
struct poly{
int constant;
int exp;
poly* next;
};

typedef poly* poly_ptr;

poly_ptr PlusElement(poly_ptr,poly_ptr);
void AddElement(poly_ptr,int,int);
void PrintElement(poly_ptr);
void FreeElement(poly_ptr);

int main(void)
{
/*假設輸入已經排序過
condition 1: 3X^3+2X^2+X+1
condition 2: 2X^3+5
Result : 5X^3+2X^2+X+6
*/

poly_ptr condition1 = new poly;
poly_ptr condition2 = new poly;
// condition 1: 3X^3+2X^2+X+1
condition1->next = NULL;
AddElement(condition1,3,3);
AddElement(condition1,2,2);
AddElement(condition1,1,1);
AddElement(condition1,1,0);
// condition 2: 2X^3+5
condition2->next = NULL;
AddElement(condition2,2,3);
AddElement(condition2,5,0);
//Print Poly
PrintElement(condition1);
cout << endl;
PrintElement(condition2);
cout << endl; ..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容



[ 此文章被panasonic732在2005-01-27 18:47重新編輯 ]

此文章被評分,最近評分記錄
財富:0 (by panasonic732) | 理由: 這是範例還是??...請依照該文章類型發文在對的地方... ^^



溝溝坎坎使人長大
哭哭笑笑沐浴人生
獻花 x0 回到頂端 [樓 主] From:台灣中華電信 | Posted:2005-01-26 23:55 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.017111 second(s),query:15 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言