Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StackOnList.h"
- #include <iostream>
- #include <string>
- using namespace std;
- void StackOnList::push(int elem) {
- if (head == NULL)
- {
- Node* temp = new Node;
- temp->info = elem;
- temp->next = NULL;
- head = temp;
- }
- else
- {
- Node* temp = new Node;
- temp->info = elem;
- temp->next = head;
- head = temp;
- }
- m_quantity++;
- }
- void StackOnList::pop() {
- head = head->next;
- m_quantity--;
- }
- int StackOnList::peek() {
- return head->info;
- }
- bool StackOnList::isEmpty() {
- if (getQuantity() == 0) {
- return true;
- }
- return false;
- }
- void StackOnList::makeEmpty() {
- while (!isEmpty()) {
- pop();
- }
- }
- int StackOnList::getQuantity() {
- return m_quantity;
- }
Advertisement
Add Comment
Please, Sign In to add comment