Mozzi  version 2016-12-11-17:03
sound synthesis library for Arduino
Stack.h
1 /*
2  * Stack.h
3  *
4  * Copyright 2013 Tim Barrass.
5  *
6  * This file is part of Mozzi.
7  *
8  * Mozzi is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
9  *
10  */
11 
17 template <class T, int NUM_ITEMS>
18 class Stack
19 {
20 private:
21  T _array[NUM_ITEMS];
22  int top;
23 
24 public:
27  Stack(): top(-1)
28  {
29  }
30 
34  void push(T item)
35  {
36  if (top< (NUM_ITEMS-1)){
37  top++;
38  _array[top]=item;
39  }
40  }
41 
45  T pop()
46  {
47  if(top==-1) return -1;
48  T item =_array[top];
49  top--;
50  return item;
51  }
52 
53 };
A simple stack, used internally for keeping track of analog input channels as they are read...
Definition: Stack.h:18
T pop()
Get the item on top of the stack.
Definition: Stack.h:45
void push(T item)
Put an item on the stack.
Definition: Stack.h:34
Stack()
Constructor.
Definition: Stack.h:27