1 #ifndef TOP_H
  2 #define TOP_H
  3 #include <iostream>
  4 #include <stdlib.h>
  5 #endif
  6 #ifndef INTARRAY_H
  7 #include "intarray.h"
  8 #define INTARRAY_H
  9 #endif
 10 using namespace std;
 11 IntArray::
 12         IntArray(){
 13                 _size = DefaultArraySize;
 14                 int * tmp;
 15                 ia = new int[_size];
 16                 for (tmp = ia; tmp < (ia + _size); tmp++)
 17                         *tmp = 0;
 18         }
 19
 20 IntArray::
 21         IntArray( int sz ){
 22                 int * tmp;
 23                 if(sz < 0){
 24                    cerr << "Size must be greater than 0 and an integer\n";
 25                         exit (-1);
 26                 }
 27
 28                 _size = sz;
 29                 
 30                 ia = new int[sz];
 31                 for(tmp = ia; tmp < (ia + sz); tmp++)
 32                         *tmp = 0;
 33         }              
 34                 
 35 IntArray::
 36         IntArray( int *tmp, int sz){
 37                 
 38                 if(sz < 0){
 39                         cerr << "Size must be greater than 0 and an integer\n";
 40                         exit(-1);
 41                 }
 42                 _size = sz;
 43                 int * tmp2;
 44                 ia = new int[sz];
 45                 for(tmp2 = ia; tmp2 < (ia + sz); tmp2++,tmp++){
 46                         *tmp2 = *tmp;//copy tmp to ia
 47                 }
 48         }
 49                                 
 50 IntArray::
 51         IntArray(const IntArray &rhs){
 52                 _size = rhs.size();
 53                 ia = new int[_size];
 54                 for(int i = 0; i < _size; i++){
 55                         ia[i] = rhs.ia[i];
 56                 }
 57         }      
 58
 59
 60         //operators
 61 bool
 62 IntArray::
 63         operator==(const IntArray &rh){
 64             bool test;
 65             int sz = size(), i;
 66             if (sz == rh.size())
 67                 test = true;
 68             else
 69                return false;
 70
 71             for(i = 0; i < 0; i++){
 72               if (ia[i] == rh.ia[i])
 73                  test = true;
 74             else
 75                   return false;
 76             }
 77             return test;
 78          }
 79
 80             
 81 int&            
 82 IntArray::
 83         operator[](int index){
 84                 if (index < 0 || index > _size)
 85                         exit (-1);
 86                 return ia[index];
 87         }      
 88 bool
 89 IntArray::
 90         operator!=(const IntArray &rh){
 91             bool test;
 92             int sz = size(), i;
 93             if (sz != rh.size())
 94                 return test = true;
 95
 96             for(i = 0; i < 0; i++){
 97               if (ia[i] != rh.ia[i])
 98                  return true;
 99             else
100                   test = false;
101             }
102         return test;    
103         }
104
105         //assignment operator
106 IntArray&
107 IntArray::
108         operator=(const IntArray &rh){
109            int sz = rh.size(), *tmp, *tmp2, *last;
110            delete [] ia;
111            int * ia = new int[sz];
112            tmp = ia;
113            last = (tmp + sz - 1);
114            for (tmp2 = rh.ia; tmp <= (last); tmp++){
115                 tmp2++;
116                 *tmp = *tmp2;
117            }
118            return *this;      
119         }
120
121 IntArray&
122 IntArray::
123         operator=(const int *rh){
124            int sz = sizeof rh, *tmp, *tmp2, *last;
125            delete [] ia;
126            int * ia = new int[sz];
127            tmp = ia;
128            last = (tmp + sz - 1);
129            for (tmp2 = rh; tmp <= (last); tmp++){
130                 tmp2++;
131                 *tmp = *tmp2;
132            }
133            return *this;      
134         }
135 inline int
136 IntArray::
137         size() const{
138                 return _size;
139         }
140
141 void
142 IntArray::
143         sort(){
144         //good ole bubble sort
145             int *x, y , *indx, *end, sizeless;
146             sizeless = (size() - 1);
147             end = (ia + sizeless);
148             for( indx = ia; indx <= end; indx++){
149                 for(x = ia; x < end; x++){
150                         if( *x > *(x + 1)){
151                                 y = *x;
152                                 *x = *(x + 1);
153                                 *(x + 1) = y;
154                         }
155                 }
156             }
157         }  
158
159 int
160 IntArray::
161         min() const{
162            int low, *tmp = ia;
163            for(low = *tmp;tmp < (ia + _size); tmp++){
164               if (*tmp < low)
165                  low = *tmp;
166             }  
167
168             return low;
169          }
170
171 int
172 IntArray::
173         max() const{
174            int high, *tmp = ia;
175            for(high = *tmp;tmp < (ia + _size); tmp++){
176               if (*tmp > high)
177                  high = *tmp;
178             }  
179
180             return high;
181          }
182
183 int
184 IntArray::
185         find( int value) const{
186         int * tmp = ia;
187         for(;tmp < (ia + _size); tmp++){
188              if(value == *tmp)
189                 return value;
190            }
191            return (-1);        
192         }
193                 
194
195
196
197
198