#ifndef TOP_H
#define TOP_H
#include <iostream>
#include <stdlib.h>
#endif
#ifndef INTARRAY_H
#include "intarray.h"
#define INTARRAY_H
#endif
using namespace std;
IntArray::
        IntArray(){
                _size = DefaultArraySize;
                int * tmp;
                ia = new int[_size];
                for (tmp = ia; tmp < (ia + _size); tmp++)
                        *tmp = 0;
        }

IntArray::
        IntArray( int sz ){
                int * tmp;
                if(sz < 0){
                   cerr << "Size must be greater than 0 and an integer\n";
                        exit (-1);
                }

                _size = sz;
                
                ia = new int[sz];
                for(tmp = ia; tmp < (ia + sz); tmp++)
                        *tmp = 0;
        }              
                
IntArray::
        IntArray( int *tmp, int sz){
                
                if(sz < 0){
                        cerr << "Size must be greater than 0 and an integer\n";
                        exit(-1);
                }
                _size = sz;
                int * tmp2;
                ia = new int[sz];
                for(tmp2 = ia; tmp2 < (ia + sz); tmp2++,tmp++){
                        *tmp2 = *tmp;//copy tmp to ia
                }
        }
                                
IntArray::
        IntArray(const IntArray &rhs){
                _size = rhs.size();
                ia = new int[_size];
                for(int i = 0; i < _size; i++){
                        ia[i] = rhs.ia[i];
                }
        }      


        //operators
bool
IntArray::
        operator==(const IntArray &rh){
            bool test;
            int sz = size(), i;
            if (sz == rh.size())
                test = true;
            else
               return false;

            for(i = 0; i < 0; i++){
              if (ia[i] == rh.ia[i])
                 test = true;
            else
                  return false;
            }
            return test;
         }

            
int&            
IntArray::
        operator[](int index){
                if (index < 0 || index > _size)
                        exit (-1);
                return ia[index];
        }      
bool
IntArray::
        operator!=(const IntArray &rh){
            bool test;
            int sz = size(), i;
            if (sz != rh.size())
                return test = true;

            for(i = 0; i < 0; i++){
              if (ia[i] != rh.ia[i])
                 return true;
            else
                  test = false;
            }
        return test;    
        }

        //assignment operator
IntArray&
IntArray::
        operator=(const IntArray& rh){
           int sz = rh.size(), *tmp, *tmp2;
           delete [] ia;
           int * ia = new int[sz];
           tmp = ia;
           for (tmp2 = rh.ia; tmp < (tmp + sz); tmp++){
                tmp2++;
                *tmp = *tmp2;
           }
           return *this;      
        }

inline int
IntArray::
        size() const{
                return _size;
        }

void
IntArray::
        sort(){
        //good ole bubble sort
            int *x, y , *indx, *end, sizeless;
            sizeless = (size() - 1);
            end = (ia + sizeless);
            for( indx = ia; indx <= end; indx++){
                for(x = ia; x < end; x++){
                        if( *x > *(x + 1)){
                                y = *x;
                                *x = *(x + 1);
                                *(x + 1) = y;
                        }
                }
            }
        }  

int
IntArray::
        min() const{
           int low, *tmp = ia;
           for(low = *tmp;tmp < (ia + _size); tmp++){
              if (*tmp < low)
                 low = *tmp;
            }  

            return low;
         }

int
IntArray::
        max() const{
           int high, *tmp = ia;
           for(high = *tmp;tmp < (ia + _size); tmp++){
              if (*tmp > high)
                 high = *tmp;
            }  

            return high;
         }

int
IntArray::
        find( int value) const{
        int * tmp = ia;
        for(;tmp < (ia + _size); tmp++){
             if(value == *tmp)
                return value;
           }
           return (-1);        
        }