Incompetent C Programming Example
I have been bothered by the C coding samples I commonly find on the Web. Almost all of them contain grievous defects. The following example of an array-based stack using C is based upon C code published at http://www-cs.ccny.cuny.edu/~peter/dstest.html The C code published at http://www-cs.ccny.cuny.edu/~peter/dstest.html supports the book Advanced Data Structures authored by Peter Braß and published by Cambridge University Press. Array Stack The C code for Array Stack is shown below. Example 1 ArrayStack.c #include <stdio.h> #include <stdlib.h> typedef int item_t; typedef struct {item_t *base; item_t *top; int size;} stack_t; stack_t *create_stack(int size) { stack_t *st; st = (stack_t *) malloc( sizeof(stack_t) ); st->base = (item_t *) malloc( size * sizeof(item_t) ); st->size = size; st->top = st->base; ...