Question: stacks.cpp #include #include Stack.h using namespace std; int main(int argc, const char * argv[]) { { Stack s1; for (int i = 1; i stack.h

 stacks.cpp #include #include "Stack.h" using namespace std; int main(int argc, const

stacks.cpp

#include  #include "Stack.h" using namespace std; int main(int argc, const char * argv[]) { { Stack s1; for (int i = 1; i  

stack.h

#pragma once #include

struct Stack {

struct Link { void* data; Link* next;

void initialize(void* dat, Link* nxt) { data = dat; next = nxt; } }*head;

void initialize() { head = 0; }

void push(void* dat) { Link* newLink = new Link; newLink->initialize(dat, head); head = newLink; }

void* peek() { if (head == 0) { std::cout data; }

void* pop() { if (head == 0) return 0;

void* result = head->data; Link* oldHead = head; head = head->next; delete oldHead; return result; }

void cleanup() { if (head == 0) { std::cout Extend the file stack.h containing Stack class given in order for it to store double numbers (instead of void* pointers). Add a destructor that will delete all the stack by making calls to pop(), and for each element destroyed the element will be printed to the output. Now add two constructors: the default one that will create an empty stack, and another one that will receive an integer n and will build a stack of n elements, such that the first element is 1.0, and the next ones are incremented of 0.1. Upload your Stack class. It will be then tested for correctness with stacks.cpp. Sample output from stacks.cpp 2 1.5 1 0.5 1.3 1.2 1.1 1 end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!