Inserting and Removing elements in a dynamic array

I'm having trouble with inserting and removing a element from a dynamic array and I would like some guidance on where to start off. Also, i am having issues obtaining a list of elements with an array and checking to see if it is in the array or not.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>

using namespace std;

const int MIN = 0;
const int MAX = 255;

class IntegerSet
{
	private:
		int *aPtr;
		int array;
	
	public:
	   IntegerSet();
       IntegerSet(int m);
       IntegerSet(int arr[], int n);
       int elements (int arr[]) const; //Need help with
       bool isElem(int m) const;       //Need help with
       IntegerSet &insert(int k); //allow cascading calls // Need help with
       IntegerSet &remove(int k);        //Need help with
};
IntegerSet::IntegerSet()
{
   array = MIN;
   aPtr = new int[array];
   for(int i = 0; i<array; i++)
   {
   	aPtr[i] = 0;
   }
}

IntegerSet::IntegerSet(int m)
{
  array = m + 1;
  aPtr = new int [array];
  for(int i = 0; i<array; i++)
  {
  	aPtr[i] = 0;
  }
}

IntegerSet::IntegerSet( int arr[], int n)
{
   array = n;
   aPtr = new int[n];
   for (int i = 0; i<n; i++)
   {
   	aPtr[i] = 0;
   }
   for (int j = 0; j<n; j++)
   {
   	if (arr[j]<=MAX && arr[j]>=0)
   	{
   		aPtr[arr[j]] = 1;
	   }
   }
}

int IntegerSet::elements (int arr[]) const
{
	return arr[255];
}

bool IntegerSet::isElem(int m) const
{
   if(m>255)
   {
       return false;
   }
   else
   {
       return true;
   }
}

IntegerSet& IntegerSet::insert(int k)
{
	array[k] = 1;
    IntegerSet temp = new IntegerSet(a);
    return temp;
}

IntegerSet& IntegerSet::remove(int k)
{
    array[k] = 0;
    IntegerSet temp = new IntegerSet(a);
    return temp;
      
}
Topic archived. No new replies allowed.