All pastes #236483 Raw Edit

Untitled

public cpp v1 · immutable
·published 2006-11-03 20:43 UTC
rendered paste body
template <class T>void set<T>::add(T num){        if (pos == length - 1){                //resize the array                T *temp = new T[length * 2];                int i;                for (i = 0; i < this->getSize(); i++){                        temp[i] = data[i];                }                delete data;                data = temp;        }        if (!this->contains(num)){                if (pos == 0)                        data[pos] = num;                else if (num > data[pos - 1])                        data[pos] = num;                else if (num < data[pos]){                        T *t = new T[pos];                        t[0] = num;                        int i;                        for (i = 1; i < pos; i++){                                t[i] = data[i - 1];                        }                        delete data;                        data = t;                }                pos++;                if (pos > length){                        length++;                }        }}