VECTOR(3C++) — MISC. REFERENCE MANUAL PAGES
NAME
vector − generic vector and stack
SYNOPSIS
#include <vector.h>
declare(vector,element_type);
implement(vector,element_type);
delcare(stack,element_type);
implement(stack,element_type);
vector(element_type) vec(size);
stack(element_type) stk(size);
DESCRIPTION
This set of macros provides two generic types vector and stack , where stack is a derived class from vector. These two templates can be instantiated to multiple versions and provide the capability of the parameterized types. Following the same patten in this header file, users can create other generic types.
For class vector , the follwoing member functions are defined
vector(element_type) (size)
This constructor allocates a block of memory that is capable of holding size elements of element_type.
vector(element_type) (vector(element_type) &)
This constructor creates the vector by initializing it with another vector.
~vector(element_type) ()
The destructor.
vector(element_type)& operator=(vector(element_type) &)
This defines the assignment opeartor.
int size()
This returns the size of the vector.
element_type& elem(int i)
This returns the ith element of the vector.
element_type& operator[](int i)
This overloads the [] operator. It returns the ith element of the vector.
void set_size(int)
This changes the size of the vector.
For class stack , the following member functions are defined:
stack(element_type) (size)
This constructor creates a stack with size elements.
stack(element_type) (stack(element_type) &)
This constructor creates a stack by initializing it with another stack.
void push(element_type &)
Push an element into the stack. If overflow call the error handling function.
element_type pop()
Pop an element out of the stack. If underflow call the error handling function.
element_type& top()
Return the top element in the stack. If the stack is empty, call the error handling function.
EXAMPLE
This example declares and uses a stack of integers.
#include <stdio.h>
#include <vector.h>
declare(vector,int);
implement(vector,int);
declare(stack,int);
implement(stack,int);
const int size = 10;
main() {
stack(int) a(size);
for (int i = 0 ; i <= size ; i++) {
a.push(i ∗ 6);
printf("push #i%d0,i+1);
fflush(stdout);
}
}
SEE ALSO
BUGS
Sun Release 4.0 — Last change: 25 August 1989