aalhour / aalhour/C-Sharp-Algorithms

Enumerating the circular buffer does not produce anything

Open
#155 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
6.2k
Forks
1.4k
PR merge metrics
No merged PRs in 30d

Description

After adding some random items to the circular buffer, using foreach or any function to enumerate the buffer does not produce anything

Here is a sample code:

`int[] values = new int[20];
Random rnd = new Random();

for (int i = 0; i < values.Length; i++)
values[i] = rnd.Next(1, 99);

CircularBuffer buffer = new CircularBuffer(values.Length / 2);

Console.WriteLine(string.Join(", ", values));

foreach (int value in values)
buffer.Add(value);

Console.WriteLine(string.Join(", ", buffer));

Console.ReadKey();`

**Expected behavior**
2 lines should be printed: 1 for the array content joined by ',' and another line for the content of the buffer joined by ','

Contributor guide

Open the contributing guide

Research direction

Look at the CircularBuffer class, likely in the DataStructures folder. The issue is that enumeration (foreach) doesn't work after adding items. Check the GetEnumerator method and how the buffer tracks items. Write a test using the provided sample code to reproduce the problem, then fix the enumeration logic.

Written by the indexing model from the issue text.

Assessment

Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.