Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The STACK class For your stack class, the header file, stack.h , should look like: #ifndef __STACK_INCLUDED__ #define __STACK_INCLUDED__ #include typedef struct stack STACK; extern

The STACK class

For your stack class, the header file, stack.h, should look like:

 #ifndef __STACK_INCLUDED__ #define __STACK_INCLUDED__ #include  typedef struct stack STACK; extern STACK *newSTACK(void (*d)(FILE *,void *)); extern void push(STACK *items,void *value); extern void *pop(STACK *items); extern void *peekSTACK(STACK *items); extern int sizeSTACK(STACK *items); extern void displaySTACK(FILE *,STACK *items); extern void visualizeSTACK(FILE *,STACK *items); #endif 

The header file contains the function signatures of your public methods while the code module, stack.c, contains their implementations. The only local includes that stack.c should have are stack.h and the header file of the underlying data structure on which the array is based.

Method behavior

Here are some of the behaviors your methods should have. This listing is not exhaustive; you are expected, as a computer scientist, to complete the implementation in the best possible and most logical manner.

newSTACK - The constructor is passed a function that knows how to display the generic value stored in the stack. That function is stored in a display field of the STACK object:

push - The push method runs in constant or amortized constant time. The value to be pushed is stored in the underlying data structure.

removeSTACK - The pop method runs in constant or amortized constant time. The value to be popped is removed in the underlying data structure.

peekSTACK - The peek method returns the value ready to come off the stack, but leaves the stack unchanged. It runs in constant time.

sizeSTACK - The size method returns the number of items stored in the stack. It runs in amortized constant time.

displaySTACK - The display method prints the items stored in the stack. If the integers 5, 6, 2, 9, and 1 are pushed in the order given, the method would generate this output:

 |1,9,2,6,5| 

with no preceding or following whitespace. An empty stack displays as ||.

visualizeSTACK - The visualize method simply calls the display method of the data structure upon which the stack is based.

Assertions

Include the following assertions in your methods:

newSTACK - The memory allocated shall not be zero.

pop - The size shall be greater than zero.

peekSTACK - The size shall be greater than zero.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

1583473858, 978-1583473856

More Books

Students also viewed these Databases questions

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago