Example – HP Integrity NonStop J-Series User Manual
Page 142

Click on the banner to return to the user guide home page.
©Copyright 1996 Rogue Wave Software
Example
Here is an example that uses an
RWGStack
, a generic stack, to store a set of pointers to ints in a
last-in, first-out (LIFO) stack. We will go through it line-by-line and explain what is happening:
#include
#include
declare(RWGStack, int) //3
main(){
RWGStack(int) gs; //4
gs.push(new int(1)); //5
gs.push(new int(2)); //6
gs.push(new int(3)); //7
gs.push(new int(4)); //8
cout << "Stack now has " << gs.entries()
<< " entries\n"; //9
int* ip; //10
while( ip = gs.pop() ) //11
{
cout << *ip << "\n"; //12
delete ip;
}
return 0;
}
Program Output:
Stack now has 4 entries
4
3
2
1
This manual is related to the following products: