#include "ICopy.h"
#include "Queue.h"
void ForEachNumber(String,int);
void setup()
{
Serial.begin(115200);
MicroBeaut_IQueue<String> numbers(5);
numbers.Enqueue("one");
numbers.Enqueue("two");
numbers.Enqueue("three");
numbers.Enqueue("four");
numbers.Enqueue("five");
// A queue can be used ForEach with Action<T>.
numbers.ForEach(ForEachNumber);
Serial.print("\nDequeuing ");
Serial.println(numbers.Dequeue());
Serial.print("Peek at next item to dequeue: ");
Serial.println(numbers.Peek());
Serial.print("\nDequeuing ");
Serial.println(numbers.Dequeue());
// Create an array twice the size of the queue and copy the
// elements of the queue, starting at the middle of the
// array.
Serial.println("\nCopyTo:");
String array2[numbers.Count * 2];
numbers.CopyTo(array2, numbers.Count);
for(int index = 0; index < numbers.Count * 2; index++) {
Serial.println(array2[index]);
}
Serial.print("\nnumbers.Contains(\"four\") = ");
Serial.println(numbers.Contains("four"));
Serial.println("\nnumbers.Clear()");
numbers.Clear();
Serial.print("\nqueueCopy.Count = ");
Serial.println(numbers.Count);
}
void loop() {
}
void ForEachNumber(String number, int index){
Serial.println(number);
}
/* This code example produces the following output:
one
two
three
four
five
Dequeuing 'one'
Peek at next item to dequeue: two
Dequeuing 'two'
Contents of the copy:
three
four
five
Contents of the second copy, with duplicates and nulls:
three
four
five
queueCopy.Contains("four") = True
queueCopy.Clear()
queueCopy.Count = 0
*/