Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. T& operator[](int i) {
  2. auto p = head;
  3. if (i >= numElems || i < 0)
  4. throw std::exception("out of range!");
  5.  
  6. int ctrTot = 0; // to get to i
  7. int ctrNode = 0; // keeps resetting for each new node
  8. while (ctrTot <= i) {
  9. if (ctrNode == nodeSize) {
  10. ctrNode = -1;
  11. p = p->next;
  12. }
  13. ctrNode++;
  14. ctrTot++;
  15. }
  16.  
  17. return p->elements[ctrNode]; // returns the value
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement