 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
string
& list::operator [] (int index) const {
|
|
node * current = head;
|
|
for (int i=0; i< index &&
current; i++)
|
|
current = current->next;
|
|
if (!current) {
|
|
//consider what other alternatives there
are
|
|
string * temp = new string; //just in
case
|
|
return *temp;
|
|
}
|
|
return current->obj;
|
|
}
|
|
|
| • |
Notice
how we must consider each special case (such as an
|
|
|
index
that goes beyond the number of nodes provided in the
|
|
linked
list
|
|