/*
多項式運算
順序棧實現
在demo1.cpp基礎上增加 彌補異常處理 以及多位數運算缺點
*/#include#include#include#define ok 1
#define error 2
#define overflow -1
#define ini_size 100
typedef int elemtype_int;
typedef char elemtype_char;
typedef int statue;
typedef structstack_int;
typedef structstack_char;
statue ini_int(stack_int *stack)
stack->ptop_int=stack->pbottom_int;
stack->stack_int_size=ini_size;
return ok;
}statue ini_char(stack_char *stack)
stack->ptop_char=stack->pbottom_char;
stack->stack_char_size=ini_size;
return ok;
}statue push_int(stack_int *stack,int val)
stack->ptop_int=stack->pbottom_int+stack->stack_int_size;
} *stack->ptop_int=val;
stack->ptop_int++;
return ok;
}statue push_char(stack_char *stack,char val)
stack->ptop_char=stack->pbottom_char+stack->stack_char_size;
} *stack->ptop_char=val;
stack->ptop_char++;
return ok;
}statue pop_int(stack_int *stack,int *val)
stack->ptop_int--;
*val=*stack->ptop_int;
return ok;
}statue pop_char(stack_char *stack,char *val)
stack->ptop_char--;
*val=*stack->ptop_char;
return ok;
}bool in(char val)else
}char gettop(stack_char stack)
char precade(char a,char b),
, ,
, ,
, };
switch(a)
switch(b)
return pre[i][j];
}int operate(int a,char val,int b)
}void show(stack_int stack)
printf("\n");
}void run(char *val)else
} if(*val=='#')
val++; }
reslute=*(s_int.ptop_int-1);
show(s_int);
printf("結果:%d\n",reslute);
}bool ischar(char val)
return false;
}bool iskuo(char q)'||q==']')
return false;
}bool isempty(stack_char stack)
return false;
}bool judge(char *val)
p++;
//#後面必須為數字
if(!in(*p))
//滿足以上條件後開始遍歷
while(*val)else
} if(ischar(*val))
} val++;
} val--;
if(*val!='#')
//判斷括號是否合法
while(*q)else
if(*q==')'&&*(stack.ptop_char-1)=='('||*q=='>'&&*(stack.ptop_char-1)=='<'||*q=='}'&&*(stack.ptop_char-1)=='else
}}else
} if(isempty(stack))
return true;
}int main(void)else
return 0;
}
VC多項式運算
多項式運算主要是係數和指數的處理,本文用乙個簡單的例子實現該功能。首先,新建控制台應用程式 然後,新建類 標頭檔案 polynomial.h inte ce for the cpolynomial class.if defined afx polynomial h 06b9bccd 1789 483...
多項式運算封裝
update on 21.12.30 新增了polyeva 修補了polymod處多測時可能產生的 bug。update on 22.2.7 重 寫 前一版太醜了 改為完全封裝版本 使用std vector存放多項式係數,運算在命名空間polynomial 裡 實現的並不優秀,但應該很穩 霧 全部提...
2 10多項式及其運算
1 多項式的表達與建立 matlab約定n次多項式用乙個長度為n 1的係數行向量來表示,按降冪排列,缺少的冪次項係數為0.2 多項式的運算 多項式的運算由四則運算符和運算函式組成,主要如下 1 多項式加減運算,維數必須相同 2 多項式乘運算 利用函式c conv a,b 3 多項式除運算 利用函式 ...