April
1999 QUESTION 4 Total Marks: 20 Marks |
Click here to access other
questions
Click to access
|
(a) | Assume the following definition of a linear
linked list as the representation of the elements of a stack: typedef struck stack_element { typedef struct {
|
|
(i) Write a procedure, push - which has the procedure prototype
shown below - that will push element x onto the stack stack. void push(StackType *stack, int x);
|
[4] | |
(ii) Write a function, isempty - which has the function prototype shown
below - that will return 1 if the stack stack is empty, and will return 0 otherwise. int isempty(StackType stack);
|
[2] | |
(iii) Write a function, sizeStack - which has the function prototype
shown below - that will return the number of element in the stack stack. int sizeStack(StackType stack);
|
[4] | |
(iv) Write a procedure, pop - which has the procedure prototype shown
below - that will return and then remove the top element from the stack stack. You should call the procedure error (with prototype given below) if it is not
possible to remove an element from the stack. void
pop(StackType *stack); Note: You are not required to write the error procedure.
|
[5] | |
(b) | Trace the following code segment and write down
the output produced: typedef struct { void main(void) { x.a = 42; y.a=1999; printf("x.a = %d\n", x.a);
|