source: abuse/trunk/src/stack.cpp @ 2

Last change on this file since 2 was 2, checked in by Sam Hocevar, 14 years ago
  • imported original 0.7.0 tarball
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.