Function description:
1.get a node's value
2.print a queue
3.Find previous node
//queue.cpp
//H.Y.Q
//Mar 08, 2013
//Release v0.2
//Get the data's value of current Node
int Queue::get(const Node* currentNode) const {
return currentNode->_data;
}
//Print the Node's data value in the queue
void Queue::print(){
Node* toPrint = _head;
int i=0;
while ((toPrint !=0) &&
(cout << (++i)<< ". Data: "<< get(toPrint) << "\tAddress: " << (void*) toPrint << endl) &&
(toPrint = nextNode(toPrint)));
}
//Return the previous Node of current Node
Node* Queue::prevNode(const Node* currentNode) const{
Node* prev = _head;
while (prev != 0 && nextNode(prev) != currentNode){
prev = nextNode(prev);
}
return prev;
}
No comments:
Post a Comment