Skip to content

Instantly share code, notes, and snippets.

@ryanwarsaw
Created April 25, 2018 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanwarsaw/7d1d1a4445c901535a7917082d2f20d8 to your computer and use it in GitHub Desktop.
Save ryanwarsaw/7d1d1a4445c901535a7917082d2f20d8 to your computer and use it in GitHub Desktop.
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