1 /*****************************************************************
2 * SQUID - a library of functions for biological sequence analysis
3 * Copyright (C) 1992-2002 Washington University School of Medicine
5 * This source code is freely distributed under the terms of the
6 * GNU General Public License. See the files COPYRIGHT and LICENSE
8 *****************************************************************/
11 * SRE, Thu Mar 3 10:08:48 1994
13 * Implementation of generic stack structures.
14 * RCS $Id: stack.c 217 2011-03-19 10:27:10Z andreas $ (Original squid RCS Id: stack.c,v 1.2 1998/10/09 18:07:16 eddy Exp)
25 /************************************************************
26 * intstack_s implementation.
28 * Functions: InitIntStack() - returns ptr to new stack
29 * PushIntStack() - (void)
30 * PopIntStack() - returns 1 on success, 0 if stack empty
31 * FreeIntStack() - returns number of elements free'd, or 0 if
34 * Implementation of the pushdown stack for storing single
36 *************************************************************/
40 struct intstack_s *stack;
42 if ((stack = (struct intstack_s *) malloc (sizeof(struct intstack_s))) == NULL)
43 Die("Memory allocation failure at %s line %d", __FILE__, __LINE__);
48 PushIntStack(struct intstack_s *stack, int data)
50 struct intstack_s *new;
52 if ((new = (struct intstack_s *) malloc (sizeof(struct intstack_s))) == NULL)
53 Die("Memory allocation failure at %s line %d", __FILE__, __LINE__);
56 new->nxt = stack->nxt;
61 PopIntStack(struct intstack_s *stack, int *ret_data)
63 struct intstack_s *old;
65 if (stack->nxt == NULL) return 0;
68 stack->nxt = old->nxt;
70 *ret_data = old->data;
76 ReverseIntStack(struct intstack_s *stack)
78 struct intstack_s *old;
79 struct intstack_s *new;
85 new = old; /* remove one from top of old stack */
87 new->nxt = stack->nxt; /* push it onto new stack */
93 FreeIntStack( struct intstack_s *stack )
98 while (PopIntStack(stack, &data))