Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // operationStack.h
- // hw2
- //
- // Created by Dolendra Subedi on 3/15/18.
- // Copyright © 2018 Paul. All rights reserved.
- //
- #ifndef myStack_h
- #define myStack_h
- #include "Node.h"
- #include <iostream>
- using namespace std;
- template <class T>
- class myStack{
- public:
- Node<T>* top;
- myStack();
- bool isEmpty();
- Node<T>* pop();
- T peek();
- void push(T);
- };
- template <class T>
- myStack<T>::myStack(){
- top=NULL;
- }
- template <class T>
- bool myStack<T>:: isEmpty(){
- if (top==NULL) {
- return true;
- }
- return false;
- }
- template <class T>
- Node<T>* myStack<T>:: pop(){
- if (top==NULL) {
- cout<<"empty"<<endl;
- return NULL;
- }
- Node<T>* temp = top;
- top=temp->down;
- return temp;
- }
- template <class T>
- T myStack<T>::peek(){
- if (top==NULL) {
- return NULL;
- }
- return top->val;
- }
- template <class T>
- void myStack<T>::push(T s){
- Node<T>* newNode=new Node<T>(s);
- if (top==NULL) {
- top= newNode;
- return;
- }
- Node<T>* temp=top;
- newNode->down=temp;
- top=newNode;
- }
- #endif /* myStack_h */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement