Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <string>
- #include <cstdio>
- using namespace std;
- struct ListNode {
- ListNode *mNext;
- int mData;
- };
- class Queue {
- public:
- // конструктор
- Queue() {
- mHead = nullptr;
- }
- // деструктор
- ~Queue() {
- ListNode *cur = mHead;
- ListNode *before;
- while (cur != nullptr) {
- before = cur->mNext;
- delete cur;
- cur = before;
- }
- }
- void pop() {
- ListNode *dl = mHead;
- while (dl->mNext != nullptr) {
- dl = dl->mNext;
- }
- delete dl->mNext;
- dl->mNext = nullptr;
- }
- void push(const int tag) {
- ListNode *new_el = new ListNode;
- new_el->mData = tag;
- new_el->mNext = mHead;
- mHead = new_el;
- }
- int top() {
- return mHead->mData;
- }
- bool empty() {
- return mHead == nullptr;
- }
- size_t size() {
- ListNode *cur = mHead;
- size_t kl = 0;
- while (cur != nullptr) {
- cur = cur->mNext;
- kl++;
- }
- return kl;
- }
- private:
- protected:
- ListNode *mHead;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement