Question
in C++ #ifndef STACK_H #define STACK_H #include struct Stack { struct Link { void* data; Link* next; void initialize(void* dat, Link* nxt){ data = dat;
in C++
#ifndef STACK_H #define STACK_H
#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
Input.txt
-----------------------------------------
16.0 2.3 -4.5 22.0 -0.4 87 34.9 -40.1 -10.5 8.8 101.4 2.56 -3.14 9.78 12.3 -3.1 1.2
----------------------------------
Consider the file Stack.h. This file contains the Stack data structure from Chapter 4 of the textbook. Your task is to write a program that declares an instance of Stack, fills it up with double numbers and then prints out the numbers. You have to use the Stack member functions to complete this exercise (except for printing). You need to read a file called input.txt, which contains floating points numbers at each line. Read in these values, store them in your Stack object and print out the values in the reverse order without deleting them from the stack (for printing you can directly access member variables). After the double values have been printed out, free the Stack by removing all elements with the pop() function. When the stack is empty, call the cleanup() function. Input input is in input.txt Output 1.2-3.1 12.3 9.78 -3.14 2.56 101.4 8.8 -10.5 -40.1 34.9 87 -0.4 22 -4.5 2.3 16
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started