"Fossies" - the Fresh Open Source Software Archive

Member "portfwd-0.29/tools/t_vector.cc" (7 Sep 2002, 1276 Bytes) of package /linux/privat/old/portfwd-0.29.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2   t_vector.c
    3 
    4   $Id: t_vector.cc,v 1.2 2002/09/07 02:27:51 evertonm Exp $
    5  */
    6 
    7 
    8 #include <stdlib.h>
    9 #include <iostream>
   10 
   11 #include "vector.hpp"
   12 #include "iterator.hpp"
   13 
   14 template <class T>
   15 void show(const char *name, const vector<T>& v)
   16 {
   17   std::cout << "  " << name << " = ";
   18   std::cout << v;
   19   std::cout << "\n";
   20 }
   21 
   22 int main()
   23 {
   24     const int MAX = 5;
   25     
   26     vector<int> v;
   27 
   28     std::cout << "inserindo elementos em v: ";
   29     for (int i = 0; i < MAX; ++i) {
   30       int j = i + 5;
   31     v.push(j);
   32     std::cout << j << " ";
   33     }
   34     std::cout << "\n";
   35 
   36     show("v", v);
   37     std::cout << "fazendo v.trim():\n";
   38     v.trim();
   39     show("v", v);
   40 
   41     vector<vector<int> > vv;
   42 
   43     vv.push(v);
   44     vv.push(v);
   45 
   46     std::cout << "vetor de vetores: fazendo vv.push(v) (2x):\n";
   47     show("vv", vv);
   48     
   49     std::cout << "linha 1, coluna 0: vv[1][0] = " << vv.get_at(0).get_at(1) << "\n";
   50 
   51     vector<int> u(v);
   52 
   53     std::cout << "copia obtida por construtor: u(v)\n";
   54     show("u", u);
   55 
   56     vector<int> t;
   57     t = u;
   58 
   59     std::cout << "copia obtida por atribuicao: t = u\n";
   60     show("t", t);
   61 
   62     std::cout << "fazendo t.erase():\n";
   63     t.erase();
   64     show("t", t);
   65 
   66     std::cout << "limpando u:\n";
   67 
   68     for (int i = 0; i < MAX; ++i)
   69     u.pop();
   70 
   71     show("u", u);
   72 
   73     return 0;
   74 }