Array Flashcards

1
Q

Array();

A

template <class T>
Array<T>::Array(){
elements = new T[MAX_ARR];
numElements = 0;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

~Array();

A

template <class T>
Array<T>::~Array(){
delete [] elements;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Array<T>& operator+=(const T&);

A

template <class>
Array<T>& Array<T>::operator+=(const T& t){
if (numElements < MAX_ARR){
elements[numElements++] = t;
}
return *this;
}</T></T></class>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Array<T>& operator-=(const T&);

A

template <class T>
Array<T>& Array<T>::operator-=(const T& t){
for(int i = 0; i < numElements; i++) {
if(elements[i] == t) {
for(int j = i; j < numElements - 1; j++) {
elements[j] = elements[j + 1];
}
numElements–;
break;
}
}
return *this;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

T& operator[](int index);

A

template <class T>
T& Array<T>::operator{
if (index < 0 || index >= numElements) {
cerr«“Array index out of bounds”«endl;
exit(1);
}
return elements[index];
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

const T& operator[](int index) const;

A

template <class T>
const T& Array<T>::operator const{
if (index < 0 || index >= numElements) {
cerr«“Array index out of bounds”«endl;
exit(1);
}
return elements[index];
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly