From 8c33a70ffa843a5a866869104dc3e892800f6620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Portela?= Date: Mon, 15 Feb 2021 23:44:13 +0000 Subject: [PATCH] Add example code --- .../CircularBufferExample.csproj | 4 ++ CircularBufferExample/Program.cs | 38 ++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CircularBufferExample/CircularBufferExample.csproj b/CircularBufferExample/CircularBufferExample.csproj index d453e9a..0c0448c 100644 --- a/CircularBufferExample/CircularBufferExample.csproj +++ b/CircularBufferExample/CircularBufferExample.csproj @@ -5,4 +5,8 @@ netcoreapp3.1 + + + + diff --git a/CircularBufferExample/Program.cs b/CircularBufferExample/Program.cs index 26c7bdf..1c9c7e2 100644 --- a/CircularBufferExample/Program.cs +++ b/CircularBufferExample/Program.cs @@ -1,4 +1,5 @@ using System; +using CircularBuffer; namespace CircularBufferExample { @@ -6,7 +7,42 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + CircularBuffer buffer = new CircularBuffer(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 buffer) + { + for (int i = 0; i < buffer.Size; i++) + { + Console.WriteLine($"buffer[{i}] = {buffer[i]}"); + } } } }