Skip to content

Commit 8c33a70

Browse files
committed
Add example code
1 parent 5e7e779 commit 8c33a70

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

CircularBufferExample/CircularBufferExample.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
</PropertyGroup>
77

8+
<ItemGroup>
9+
<ProjectReference Include="..\CircularBuffer\CircularBuffer.csproj" />
10+
</ItemGroup>
11+
812
</Project>

CircularBufferExample/Program.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
11
using System;
2+
using CircularBuffer;
23

34
namespace CircularBufferExample
45
{
56
class Program
67
{
78
static void Main(string[] args)
89
{
9-
Console.WriteLine("Hello World!");
10+
CircularBuffer<int> buffer = new CircularBuffer<int>(5, new[] {0, 1, 2});
11+
Console.WriteLine("Initial buffer {0,1,2}:");
12+
PrintBuffer(buffer);
13+
14+
15+
for (int i = 3; i < 7; i++)
16+
{
17+
buffer.PushBack(i);
18+
}
19+
Console.WriteLine("\nAfter adding a 7 elements to a 5 elements capacity buffer:");
20+
PrintBuffer(buffer);
21+
22+
23+
buffer.PopFront();
24+
Console.WriteLine("\nbuffer.PopFront():");
25+
PrintBuffer(buffer);
26+
27+
28+
buffer.PopBack();
29+
Console.WriteLine("\nbuffer.PopBack():");
30+
PrintBuffer(buffer);
31+
32+
for (int i = 2; i >= 0; i--)
33+
{
34+
buffer.PushFront(i);
35+
}
36+
Console.WriteLine("\nbuffer.PushFront() {2,1,0} respectively:");
37+
PrintBuffer(buffer);
38+
}
39+
40+
private static void PrintBuffer(CircularBuffer<int> buffer)
41+
{
42+
for (int i = 0; i < buffer.Size; i++)
43+
{
44+
Console.WriteLine($"buffer[{i}] = {buffer[i]}");
45+
}
1046
}
1147
}
1248
}

0 commit comments

Comments
 (0)