1 /*****************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 *****************************************************************/
12 * SRE, Thu Mar 3 10:08:48 1994
14 * Implementation of generic stack structures.
15 * RCS $Id: stack.c,v 1.1.1.1 2005/03/22 08:34:25 cmzmasek Exp $
26 /************************************************************
27 * intstack_s implementation.
29 * Functions: InitIntStack() - returns ptr to new stack
30 * PushIntStack() - (void)
31 * PopIntStack() - returns 1 on success, 0 if stack empty
32 * FreeIntStack() - returns number of elements free'd, or 0 if
35 * Implementation of the pushdown stack for storing single
37 *************************************************************/
41 struct intstack_s *stack;
43 if ((stack = (struct intstack_s *) malloc (sizeof(struct intstack_s))) == NULL)
44 Die("Memory allocation failure at %s line %d", __FILE__, __LINE__);
49 PushIntStack(struct intstack_s *stack, int data)
51 struct intstack_s *new;
53 if ((new = (struct intstack_s *) malloc (sizeof(struct intstack_s))) == NULL)
54 Die("Memory allocation failure at %s line %d", __FILE__, __LINE__);
57 new->nxt = stack->nxt;
62 PopIntStack(struct intstack_s *stack, int *ret_data)
64 struct intstack_s *old;
66 if (stack->nxt == NULL) return 0;
69 stack->nxt = old->nxt;
71 *ret_data = old->data;
77 ReverseIntStack(struct intstack_s *stack)
79 struct intstack_s *old;
80 struct intstack_s *new;
86 new = old; /* remove one from top of old stack */
88 new->nxt = stack->nxt; /* push it onto new stack */
94 FreeIntStack( struct intstack_s *stack )
99 while (PopIntStack(stack, &data))