/stack-structure-using-node-structure-and-pointers

Implement the given methods of stack structure using node structure and pointers. List of stack functions is given at the end a) Create node structure that can store integers b) Create stack class, declare data members as discussed and write constructor • Write main method and create a stack object c) Write display method that display the stack each element on new line from top to bottom. Take care of s_top (it should not move or any other thing should not change) • Call this method in main to test d) Write push method that accept an integer and place it at the start of stack. Properly adjust the pointer and return bool • Call this method in main to push 21, 54, 67, 88, 44, 33, 48, 44, 109, 133 in the stack, and display to confirm e) Write push method that accept object of node and copy its data to push in stack. Properly adjust the pointer. • In main create a node with 189 and call this method to push and display to confirm f) Write pop method that remove top element from the stack and return the element value if element is removed. If stack is empty then return -9999 as sentinel value. Implement the cases as discussed in theory. Properly take care of pointers. • Call this method in main to remove an element and display to confirm Write stackSize method that returns size of stack using counter we hold in stack • Call this method in main h) Write stackSizeByPointer method that returns size of stack by traversing the stack • Call this method in main and match results from above i) Write destructor of stack that should fully empty the stack. Properly de-attach element one by one and delete form memory Constructor Set initializing values int stackSize(); Return Size of Stack int stackSizeByPointer(); Return stack size by traversing stack bool push(int); Put given element at the top of stack int pop(); Remove top element from the stack and return element int top(); Return top element of stack void display(); Display stack from top to end Destructor Empty the stack and properly delete elements from memory

Primary LanguageC++MIT LicenseMIT

Stargazers

No one’s star this repository yet.