Skip to content

Commit

Permalink
Add example code
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoportela committed Feb 15, 2021
1 parent 5e7e779 commit 8c33a70
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CircularBufferExample/CircularBufferExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CircularBuffer\CircularBuffer.csproj" />
</ItemGroup>

</Project>
38 changes: 37 additions & 1 deletion CircularBufferExample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,48 @@
using System;
using CircularBuffer;

namespace CircularBufferExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
CircularBuffer<int> buffer = new CircularBuffer<int>(5, new[] {0, 1, 2});
Console.WriteLine("Initial buffer {0,1,2}:");
PrintBuffer(buffer);


for (int i = 3; i < 7; i++)
{
buffer.PushBack(i);
}
Console.WriteLine("\nAfter adding a 7 elements to a 5 elements capacity buffer:");
PrintBuffer(buffer);


buffer.PopFront();
Console.WriteLine("\nbuffer.PopFront():");
PrintBuffer(buffer);


buffer.PopBack();
Console.WriteLine("\nbuffer.PopBack():");
PrintBuffer(buffer);

for (int i = 2; i >= 0; i--)
{
buffer.PushFront(i);
}
Console.WriteLine("\nbuffer.PushFront() {2,1,0} respectively:");
PrintBuffer(buffer);
}

private static void PrintBuffer(CircularBuffer<int> buffer)
{
for (int i = 0; i < buffer.Size; i++)
{
Console.WriteLine($"buffer[{i}] = {buffer[i]}");
}
}
}
}

0 comments on commit 8c33a70

Please sign in to comment.