Category : Files from Magazines
Archive   : CUJ9411.ZIP
Filename : STRTST7.CPP

 
Output of file : STRTST7.CPP contained in archive : CUJ9411.ZIP
Listing 2 - a test program for generic queues based on the generic.h
macros

//
// strtst7.cpp - test gueue(str)
//

#include

#include "queue7.h"
#include "showheap.h"
#include "str.h"

declare(queue, str)

ostream &operator<<(ostream &os, queue(str) &q)
{
str *ps;
queue(str)::iterator sqi(q);
while ((ps = sqi.next()) != 0)
os << ' ' << *ps;
return os;
}

#define DIM(a) (sizeof(a)/sizeof(a[0]))

void test()
{
char c;
size_t qn;
str qe;
queue(str) q[4];
while (cin >> c)
{
showheap();
if (c == 'q')
break;
if (c == 'a')
{
cin >> qn >> qe;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].append(qe);
}
else if (c == 'c')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else
q[qn].clear();
}
else if (c == 'r')
{
cin >> qn;
if (qn >= DIM(q))
cout << "no such queue\n";
else if (q[qn].remove(qe))
cout << "removed " << qe << '\n';
else
cout << "q[" << qn << "] is empty\n";
}
else
continue;
for (size_t i = 0; i < DIM(q); ++i)
cout << i << ':' << q[i] << '\n';
}
}

int main()
{
showheap();
test();
showheap();
return 0;
}



  3 Responses to “Category : Files from Magazines
Archive   : CUJ9411.ZIP
Filename : STRTST7.CPP

  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/