Example #1
0
 /** This is the delete method which is used to remove a term from polynomial */
 public void delete(int c, int e) {
   Term t = new Term(c, e);
   for (int i = 0; i < poly.size(); i++) {
     if (t.getCoe() == poly.get(i).getCoe() && t.getExp() == poly.get(i).getExp()) {
       poly.remove(i);
       break;
     } else {
       if (i == poly.size() - 1) {
         System.out.println("This term is not in the polynomial.");
       }
     }
   }
 }
Example #2
0
 /** This is the insert method which inserts a term into polynomial */
 public void insert(int c, int e) {
   Term t = new Term(c, e);
   if (poly.size() == 0) {
     poly.add(t);
   } else {
     int j = 0;
     while (j < poly.size()) {
       if (poly.get(j).getExp() >= t.getExp()) {
         poly.add(j, t);
         break;
       }
       j++;
     }
     if (j == poly.size()) {
       poly.add(t);
     }
   }
 }