TASK:
TASK H1: with each of the 4 marked statements immediately below, explain, in plain English,
a) what the statement does and
b) its purpose in the program.
const int MAXSTACKSIZE = 5; - TASK H1.1 Explain this statement
const int BOTTOMOFSTACK = -1; - TASK H1.2 Explain this statement
typedef char StackElement; -TASK H1.3 Explain this statement
TASK H1.4 Explain this statement
typedef struct {
StackElement contents[MAXSTACKSIZE];
int top;
} Stack;
Answer:
H1.1: MAXSTACKSIZE – is a constant that represents integer value 5. This variable is used in structure as a size of “contents” array.
H1.2: BOTTOMOFSTACK – is a constant that represents integer value -1. In the program this variable will represent the state when the Stack is empty -. if(top == BOTTOMOFSTACK) /*than Stack is empty*/
H1.3: StackElement – declaration of a new type that represents char(or other type you need). In C programs that approach is used to enable template classes. Each time you change the type in this typedef you changed the template specification for Stack structure.
H1.4: This statement determines new type Stack that represents template structure with array "contents" and int "top" variable. To create an instance you need: Stack [variablename];
www.assignmentexpert.com
Comments