Tranvick

Untitled

Jun 4th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. class dinarr{
  2.     int a[],t;
  3.     dinarr(){
  4.         a=new int[1];
  5.         t=0;
  6.     }
  7.     void _resize(int x){
  8.         int b[]=new int[x];
  9.         for (int i=0;i<x && i<t;++i) b[i]=a[i];
  10.         a=b;
  11.     }
  12.     void _pushb(int x){
  13.         if (t==a.length) _resize(t+t);
  14.         a[t++]=x;
  15.     }
  16.     void _popb(){
  17.         --t;
  18.     }  
  19.     int _bck(){
  20.         return a[t-1];
  21.     }
  22. }
  23.  
  24. class vector{
  25.     private dinarr f;
  26.     vector(){
  27.         f = new dinarr();
  28.     }
  29.     vector(int x){
  30.         f = new dinarr();
  31.         if (x<1) x=1;
  32.         f.a=new int[x];
  33.         f.t=0;
  34.     }
  35.     vector(int b[]){
  36.         f = new dinarr();
  37.         f.a=b;
  38.         f.t=b.length;
  39.     }
  40.     public void resize(int x){
  41.         f._resize(x);
  42.     }
  43.     public void push_back(int x){
  44.         f._pushb(x);
  45.     }
  46.     public void pop_back(){
  47.         f._popb();
  48.     }
  49.     public int back(){
  50.         return f._bck();
  51.     }
  52.     public int at(int x){
  53.         if (x<f.t) return f.a[x];
  54.         return 100500;
  55.     }
  56.     public void mod(int x,int y){
  57.         if (x<f.t) f.a[x]=y;
  58.     }
  59. }
  60.  
  61. class stack{
  62.     private dinarr f;
  63.     stack(){
  64.         f = new dinarr();
  65.     }
  66.     public void push(int x){
  67.         f._pushb(x);
  68.     }
  69.     public void pop(){
  70.         f._popb();
  71.     }
  72.     public int top(){
  73.         return f._bck();
  74.     }
  75. }
  76.  
  77. public class geom {
  78.     public static void main(String args[]){
  79.         stack s = new stack();
  80.         s.push(7);
  81.         System.out.println(s.top());
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment