Created
April 25, 2018 16:41
-
-
Save ryanwarsaw/7d1d1a4445c901535a7917082d2f20d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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