Пример #1
0
 //从游标当前位置开始构造一个B类结点
 private bool ConstructMultinomialB(out MultinomialB out1)
 {
     out1 = null;
     try
     {
         out1 = new MultinomialB(1);
     }
     catch (Exception)
     {
         Error = "内存空间不足";
         return false;
     }
     while (Seek < Fm.Length)
     {
         if (Fm[Seek] != '^' && IsOperator(Fm[Seek]) || Fm[Seek] == '(')
             break;
         else if (IsLetter(Fm[Seek]))
         {
             MultinomialA a;
             try
             {
                 a = new MultinomialA(Fm[Seek++]);
             }
             catch (Exception)
             {
                 Error = "内存空间不足";
                 return false;
             }
             if (Seek < Fm.Length && Fm[Seek] == '^')
             {
                 Double d;
                 if (!Degree(out d))
                     return false;
                 a.index = d;
             }
             out1.Insert(a);
         }
         else if (IsESC(Fm[Seek]))
             Seek++;
         else
         {
             if (IsNumber(Fm[Seek]))
                 Error = "字母后面不能直接跟数字";
             else
                 Error = "存在非法字符:\"" + Fm[Seek] + "\"";
             return false;
         }
     }
     return true;
 }
Пример #2
0
 //B类结点的乘法运算
 public static MultinomialB MUL(MultinomialB a, MultinomialB b)
 {
     try
     {
         if (a.coefficient == 0 || b.coefficient == 0)
             return new MultinomialB(0);
     }
     catch (Exception)
     {
         throw;
     }
     MultinomialB c;
     try
     {
         c = new MultinomialB(a);
     }
     catch (Exception)
     {
         throw;
     }
     c.coefficient *= b.coefficient;
     for (int i = 0; i < b.count; i++)
         c.Insert(b.Buf[i]);
     return c;
 }