Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
template<typename T>
inline void Queue<T>::Enqueue(const T &element) {
if (this->data_->IsEmpty()) {
this->data_->AddToEnd(element);
} else {
Node<T> *node = this->data_->PeekHead();
if (node->data_ != element) {
// Issue here when inserting something into the first node.
while (node->next_ != nullptr) {
node = node->next_;
cout << element << " " << node->data_ << endl;
if (element < node->data_) {
this->data_->AddBeforeNode(element, node);
return;
}
}
this->data_->AddToEnd(element);
} // else, the element already exists in the Queue, DoNothing();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.