Category : Files from Magazines
Archive   : VOL11N14.ZIP
Filename : DYNARRAY.H

 
Output of file : DYNARRAY.H contained in archive : VOL11N14.ZIP
// dynarray.h RHS 1/7/92

#if !defined(DYNARRAY_H)
#define DYNARRAY_H

#include
#include

template
class DynArray
{
TYPE *TArray;
int size;
int num;

public:
void Init(int n)
{
TArray = new TYPE[size = n];
num = 0;
}
DynArray(int n)
{
Init(n);
}
DynArray(void)
{
TArray = NULL;
num = 0;
size = 0;
}
~DynArray() { delete[] TArray; }
TYPE& operator[](int i) { return TArray[i]; }
NumItems(void) { return size; }
void ReSize(int newsize);
void Delete(TYPE t);
void Add(TYPE t);
};

template
void DynArray::Add(TYPE t)
{
if(num == size)
ReSize(size+10);
TArray[num++] = t;
}

template
void DynArray::ReSize(int newsize)
{
if(newsize == size)
return;

TYPE *temp = new TYPE[newsize];
if(!temp)
return;
memcpy(temp,TArray,
( (newsize > size) ? (size*sizeof(TYPE)) : (newsize*sizeof(TYPE)) ));
delete TArray;
TArray = temp;
size = newsize;
}

#endif




  3 Responses to “Category : Files from Magazines
Archive   : VOL11N14.ZIP
Filename : DYNARRAY.H

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/