title: compare two bigints c++
body: <p>I've got a bigint class that uses an array called SafeArray that I created in a different class. I couldn't use vectors. The set and get function calls are from the SafeArray class. Get takes an int parameter for array position and set takes 2 int parameters (one for position and one for value). All methods in this bigint class work fine (we don't have to account for negative integers) except my compare method needs work. I want it to be able to compare two bigints and if the (const bigint and &amp;A) number is larger than the other (cout 1) if it is smaller (cout 2) if they are the same (cout 0). Any help with this method would be greatly appreciated. Thanks</p>
  
  <pre><code>int size = 35; //will get bigger, small now just for testing
  class bigint
  {
      SafeArray&lt;int&gt; *arr;
  public:
      bigint()            //initializes to zero
      {
          arr = new SafeArray&lt;int&gt;;
          for(int i =0;i &lt; size; i++)
              arr-&gt;set(i,0);
      }
  
      void print()                 //prints numbers without zeroes in front
      {
          bool start_num=false;
          for(int i = 0;i &lt;arr-&gt;get_size() ;i++)
          {
              if(arr-&gt;get(i)!=0 &amp;&amp; start_num==false )
              {start_num=true;
                  cout &lt;&lt; arr-&gt;get(i);}
           else if(start_num==true)
               cout&lt;&lt;arr-&gt;get(i);                
          }
  
         cout&lt;&lt;endl;
      }
  
      void assign(const bigint &amp;A)                  //
      {
          for(int i=0;i&lt;arr-&gt;get_size();i++)
          {                                   //Ways to initialize stuff
              arr-&gt;set(i,A.arr-&gt;get(i));
          }        
      }
  
      void assign(int num)                                     //
      {
          for(int i = arr-&gt;get_size()- 1; i &gt;= 0; i--)
          {
              arr-&gt;set(i,num%10);
              num /=10;
          }          
      }
  
      void assign(string num)                        //
      {
          long len = num.length();
          int j=arr-&gt;get_size()-1;
          for(long i=len-1;i&gt;=0;i--)
          {
              arr-&gt;set(j,num[i]-48);
              j--;
          }
      }
  
      void add(const bigint &amp;A)                    //add big ints
      {
          int carry=0;
          for(int i=size-1;i&gt;=0;i--)
             {
                 int result = arr-&gt;get(i)+A.arr-&gt;get(i)+carry;
                 arr-&gt;set(i,result%10);
                 carry=result/10;
             }
      }
  
      void subtract(const bigint &amp;A)                 //subtract big ints
      {
          int borrow = 0;
          for(int i=size-1; i &gt;= 0; --i)
          {
              int result=((arr-&gt;get(i) - A.arr-&gt;get(i) - borrow));
              if(result &lt; 0)
              {
                  arr-&gt;set(i, result + 10);
                  borrow = 1;
              }
              else
              {
                  arr-&gt;set(i, result);
                  borrow = 0;
              }
          }
      }
  
  //int compare(const bigint &amp;A)               //compare big ints
  //    {
  //        
  //        for(int i&lt;size;i&gt;0;i--)
  //            {
  //                if(A.arr-&gt;get(i) &gt; arr-&gt;get(i))
  //                    {
  //                    return 1;
  //                    }
  //                else if(A.arr-&gt;get(i) &lt; arr-&gt;get(i))
  //                    {
  //                        return -1;
  //                    }
  //                else
  //                    {
  //                        return 0;
  //                    }
  //            }
  //        
  //    }
  
  };
  int main()    
  {    
      bigint a, b, c;
  
      a.assign("12345678");                             //for testing
      b.assign("12345678");
      //a.compare(b);
      a.print();
      c.assign(24691357);        // 696969 is small enough to be an int.
      a.add(b);                // a += b;
      a.subtract(c);           // a -= b;
      a.print();
  
      return 0;
  }
  </code></pre>