Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- T& operator[](int i) {
- auto p = head;
- if (i >= numElems || i < 0)
- throw std::exception("out of range!");
- int ctrTot = 0; // to get to i
- int ctrNode = 0; // keeps resetting for each new node
- while (ctrTot <= i) {
- if (ctrNode == nodeSize) {
- ctrNode = -1;
- p = p->next;
- }
- ctrNode++;
- ctrTot++;
- }
- return p->elements[ctrNode]; // returns the value
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement