view src/stack_test.c @ 5:e117c4d93602

Added list - a doubly linked list. Fixed memory leaks in some of the test drivers.
author Eris Caffee <discordia@eldalin.com>
date Fri, 21 Sep 2012 18:42:49 -0500
parents 5af32066927f
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "stack.h"
5 #define MAX 100
7 int main(int argc, char**argv)
8 {
9 int i;
10 int *ip;
11 struct stack * s;
13 s = stack_new(MAX);
14 if (NULL == s)
15 {
16 perror("stack_new: ");
17 exit(EXIT_FAILURE);
18 }
20 for (i=0; i < MAX/2; i++)
21 {
22 ip = malloc(sizeof(int));
23 *ip = i;
24 stack_push(s, (void *) ip);
25 }
27 printf("stack size is %zd\n", stack_size(s));
28 while (NULL != (ip = stack_pop(s)))
29 {
30 printf("%d\n", *ip);
31 free(ip);
32 }
33 printf("stack size is %zd\n", stack_size(s));
35 stack_delete(s);
37 exit(EXIT_SUCCESS);
38 }