Removing in Circular buffers

SO I have this remove function that is supposed to delete an element within the active data of the circular buffer and shift to left the elements. so if my arrays is [[0]45,[1]46,[3]47,[4]48,[5]49] and I remove 47 it should look like [[0]45,[1]46,[3]48,[4]49], but no matter what I do I seem to not make it work.

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
int SSLColumn::remove(int data)
{
int index = -1;
// traverse array from the start
for (int i = m_start; i < (m_start + m_size); i++)
{
	if (m_data[i % m_capacity] == data)
	{
		index = i % m_capacity;
		cout << "index = " << index << endl;
	}
}
if (index == -1)// if not found
{
	return -1;
}
if (index == m_start) // if its at the start
{
	m_start = (m_start + 1) % m_capacity;
	m_size--;
	return index;
}
if (index == (m_end - 1 + m_capacity) % m_capacity) // if its at the end
{
	m_end = (m_end - 1 ) % m_capacity;
	m_size--;
	return index;
}
if (index > m_start && index < (m_end - 1 + m_capacity) % m_capacity) // if its in the middle it shifts to the left
{
	for (int end = m_start + m_size; end > index; end--)
	{
		m_data[end % m_capacity] = m_data[(end + 1) % m_capacity];//Shift the elements by 1 index to the left

	}
	m_end = (m_end - 1) % m_capacity;
	m_data[index] = data;
	m_size--;
	return index;
}
}

where m_size is the number of items stored in the circular buffer and m_apacity is how much space was allocated.

How can I get this shift to the left to make it work?
Last edited on
Topic archived. No new replies allowed.