source: abuse/tags/pd/abuse/src/stack.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 498 bytes
Line 
1#ifndef __STACK_HPP_
2#define __STACK_HPP_
3
4template <class T> grow_stack        // stack does not shrink
5{
6  public :
7  T **sdata;
8  long ssize,son;
9
10  grow_stack() { sdata=NULL; ssize=0; son=0; }
11  void *push(T *data)
12  { if (son>=ssize)
13    { ssize+=0x100;
14      sdata=(T **)jrealloc(sdata,sizeof(T *)*ssize,"stack");
15    }
16    sdata[son++]=data;
17  }
18   
19  T *pop(long total)
20  { if (son>total) { lbreak("stack underflow\n"); exit(0); }
21    son-=total;
22    return sdata[son];
23  }
24} ;
25
26#endif
Note: See TracBrowser for help on using the repository browser.