sample3-inl.h (googletest-release-1.11.0) | : | sample3-inl.h (googletest-release-1.12.0) | ||
---|---|---|---|---|
skipping to change at line 64 | skipping to change at line 64 | |||
QueueNode* next() { return next_; } | QueueNode* next() { return next_; } | |||
const QueueNode* next() const { return next_; } | const QueueNode* next() const { return next_; } | |||
private: | private: | |||
// Creates a node with a given element value. The next pointer is | // Creates a node with a given element value. The next pointer is | |||
// set to NULL. | // set to NULL. | |||
explicit QueueNode(const E& an_element) | explicit QueueNode(const E& an_element) | |||
: element_(an_element), next_(nullptr) {} | : element_(an_element), next_(nullptr) {} | |||
// We disable the default assignment operator and copy c'tor. | // We disable the default assignment operator and copy c'tor. | |||
const QueueNode& operator = (const QueueNode&); | const QueueNode& operator=(const QueueNode&); | |||
QueueNode(const QueueNode&); | QueueNode(const QueueNode&); | |||
E element_; | E element_; | |||
QueueNode* next_; | QueueNode* next_; | |||
}; | }; | |||
template <typename E> // E is the element type. | template <typename E> // E is the element type. | |||
class Queue { | class Queue { | |||
public: | public: | |||
// Creates an empty queue. | // Creates an empty queue. | |||
skipping to change at line 86 | skipping to change at line 86 | |||
// D'tor. Clears the queue. | // D'tor. Clears the queue. | |||
~Queue() { Clear(); } | ~Queue() { Clear(); } | |||
// Clears the queue. | // Clears the queue. | |||
void Clear() { | void Clear() { | |||
if (size_ > 0) { | if (size_ > 0) { | |||
// 1. Deletes every node. | // 1. Deletes every node. | |||
QueueNode<E>* node = head_; | QueueNode<E>* node = head_; | |||
QueueNode<E>* next = node->next(); | QueueNode<E>* next = node->next(); | |||
for (; ;) { | for (;;) { | |||
delete node; | delete node; | |||
node = next; | node = next; | |||
if (node == nullptr) break; | if (node == nullptr) break; | |||
next = node->next(); | next = node->next(); | |||
} | } | |||
// 2. Resets the member variables. | // 2. Resets the member variables. | |||
head_ = last_ = nullptr; | head_ = last_ = nullptr; | |||
size_ = 0; | size_ = 0; | |||
} | } | |||
skipping to change at line 164 | skipping to change at line 164 | |||
node = node->next_) { | node = node->next_) { | |||
new_queue->Enqueue(function(node->element())); | new_queue->Enqueue(function(node->element())); | |||
} | } | |||
return new_queue; | return new_queue; | |||
} | } | |||
private: | private: | |||
QueueNode<E>* head_; // The first node of the queue. | QueueNode<E>* head_; // The first node of the queue. | |||
QueueNode<E>* last_; // The last node of the queue. | QueueNode<E>* last_; // The last node of the queue. | |||
size_t size_; // The number of elements in the queue. | size_t size_; // The number of elements in the queue. | |||
// We disallow copying a queue. | // We disallow copying a queue. | |||
Queue(const Queue&); | Queue(const Queue&); | |||
const Queue& operator = (const Queue&); | const Queue& operator=(const Queue&); | |||
}; | }; | |||
#endif // GOOGLETEST_SAMPLES_SAMPLE3_INL_H_ | #endif // GOOGLETEST_SAMPLES_SAMPLE3_INL_H_ | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added |