An Array Implementation of a Quack
We can implement quacks as an array instead of a linked list.
Both use exactly the same .h file.
Quack is now a pointer to a struct that contains an array and an integer:
// quackAR.c: an array-based implementation of a quack
#include "quack.h"
#define HEIGHT 1000
struct _node {
int array[HEIGHT];
int top;
};
Quack createQuack(void) {
Quack qs = (Quack)malloc(sizeof(struct _node));
assert(qs != NULL);
qs->top = -1; // note the array in struct _node does not get initialised
return qs;
}
|
|