kilolilo

class append

Feb 27th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class list{
  5. public:
  6.     int size,ind,*a;
  7.     list(){
  8.         a=new int[10];
  9.         size=10;
  10.         ind=0;
  11.     }
  12.     ~list(){
  13.         delete[]a;
  14.     }
  15.     void append(int x){
  16.         if(ind==size){
  17.  
  18.             int * b=new int[size + 10];
  19.             for (int j=0;j<size;j++){
  20.                 b[j]=a[j];
  21.             }
  22.             size += 10;
  23.             delete [] a;
  24.             a = b;
  25.         }
  26.  
  27.         a[ind++]=x;
  28.     }
  29.     void print(){
  30.         for(int i=0;i<ind;i++){
  31.             cout<<a[i]<<" , ";
  32.         }
  33.     }
  34. };
  35.  
  36. int main()
  37. {
  38.     list a=list();
  39.     for(int i=1;i<25;i++){
  40.         a.append(i);
  41.     }
  42.     a.print();
  43. }
Add Comment
Please, Sign In to add comment