MUstar

IoT C++ 09/14 - MyArray_MyArray.cpp

Sep 14th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. include<iostream>
  2. #include "MyArray.h"
  3. using namespace std;
  4.  
  5. MyArray::MyArray()
  6. {
  7.     ptr = new int[size];
  8.     cnt = 0;
  9. }
  10.  
  11. void MyArray::append(int num)
  12. {
  13.     ptr[cnt++] = num;
  14. }
  15.  
  16. bool MyArray::delete_(int num)
  17. {
  18.     if(num!=1)
  19.     {
  20.         if(cnt>0)
  21.         {
  22.             cnt--;
  23.             return true;
  24.         }
  25.         else
  26.             return false;
  27.     }
  28.     else
  29.     {
  30.         delete[] ptr;
  31.         ptr=NULL;
  32.     }
  33. }
  34.  
  35. void MyArray::print()
  36. {
  37.     if(cnt==0)
  38.         cout<<"배열에 값이 비였습니다."<<endl;
  39.     else
  40.     {
  41.         for(int i=0;i<cnt;i++)
  42.         {
  43.             cout<<i+1<<"|"<<ptr[i]<<endl;
  44.         }
  45.     }
  46. }
Add Comment
Please, Sign In to add comment