I would write the two functions as follows:
Again, the header file Fardad has provided needs to be modified so that it returns by reference.
int& Queue::operator[](unsigned int index){
Node* tempNode =_head;
int i;
for (i=0; i<index%size();i++){
tempNode = tempNode->_next;
}
return tempNode->_data;
}
unsigned int Queue::size(){
Node* tempNode =_head;
unsigned int count = 0;
while (tempNode){
tempNode = tempNode->_next;
count++;
}
return count;
}
No comments:
Post a Comment