Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 //插入一个A类结点(实为多项式的乘法运算)
 public void Insert(MultinomialA a)
 {
     if (a.index == 0)
         return;
     int n = 0;
     while (n < count)
     {
         if (a.letter <= Buf[n].letter)
             break;
         n++;
     }
     if (n < count && a.letter == Buf[n].letter)
     {
         Buf[n].index += a.index;
         if (Buf[n].index == 0)
             Remove(n);
     }
     else
     {
         if (count >= M)
             Enlarge();
         if (n < count)
         {
             for (int i = count; i > n; i--)
                 Buf[i] = Buf[i - 1];
         }
         try
         {
             Buf[n] = new MultinomialA(a);
         }
         catch (Exception)
         {
             throw;
         }
         count++;
     }
 }
Ejemplo n.º 3
0
 //比较两个A类结点的大小(字母升序,指数降序)
 public static int Compare(MultinomialA a, MultinomialA b)
 {
     if (a.letter != b.letter)
         return a.letter - b.letter;
     else
         return (int)(b.index - a.index);
 }
Ejemplo n.º 4
0
 //复制构造函数
 public MultinomialB(MultinomialB a)
 {
     BM = a.BM;
     M = a.M;
     count = a.count;
     coefficient = a.coefficient;
     try
     {
         Buf = new MultinomialA[M];
         for (int i = 0; i < count; i++)
             Buf[i] = new MultinomialA(a.Buf[i]);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
 //复制构造函数
 public MultinomialA(MultinomialA a)
 {
     letter = a.letter;
     index = a.index;
 }