Stack ADT using C++

Stack ADT using C++

You are provided with a skeleton, MyStack.h,for a template stack ADT, which is implemented using a linked-list structure. Following are the methods you should implement:

  • push(): push an element onto the stack
  • pop(): remove the top element from the stack
  • peekStack():return the value of top element from stack, without removing it
  • view(): display the contents of the stack without removing them
  • isStackEmpty(): check if stack is empty
  • a constructor which initializes all attributes as necessary, as well as a destructor, which deallocates all nodes being used by the stack
  1. Part2: Testing your ADT
    Write a short test program for the ADT you’ve created in a main.cpp file, which imports the header MyStack.h using #include. The test program should:
  2. 1. Declare two stacks of different base types: int and char.
    2. Push several elements into each, pop some of the elements, and test all the remaining methods of the MyStack ADT.

#ifndef MYSTACK_H

#define MYSTACK_H_x000D_
_x000D_
#include <iostream>_x000D_
#include <stdlib.h>_x000D_
_x000D_
using namespace std;_x000D_
_x000D_
template <class Type>_x000D_
class MyStack {_x000D_
_x000D_
private:_x000D_
_x000D_
    // Declare data structure for linked list implementation of stack_x000D_
    struct MyStackNode {_x000D_
        Type data;_x000D_
        MyStackNode *next;_x000D_
    };_x000D_
_x000D_
    // Pointer to the top of stack_x000D_
    MyStackNode *top;_x000D_
_x000D_
public:_x000D_
_x000D_
    // Constructor: initialize the stack_x000D_
_x000D_
    // Destructor: remove all elements from the stack_x000D_
    _x000D_
    // isStackEmpty() - check if the stack is empty_x000D_
    _x000D_
    // push()- push a new element to the stack_x000D_
    _x000D_
    // pop() - pop an element from the stack_x000D_
    _x000D_
    // view() - display the contents of the stack without removing the_x000D_
    // items_x000D_
    _x000D_
    // peekStack() - display the top element without removing it_x000D_
    _x000D_
    _x000D_
}; // MyStack_x000D_
_x000D_
#endif // MYSTACK_H

"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper