array push() + pop()?


so there seem no array functions push(). pop() splice(), etc. wondering how folks store data sets of unknown length @ runtime - , retrieve data in loop through eq. of myarray.length - 1?


the idea comes mind right init array length large enough accommodate possible data set , keep separate index position of last stored value.


am missing built in methods?


thanks!

--roy

quote
the idea comes mind right init array length large enough accommodate possible data set , keep separate index position of last stored value.

i think that's pretty choice.  that'll how built-in stack operations end working internally anyway.  note microcontrollers avr used in arduino have quite limited amount of ram, have pretty careful how use.


code: [select]
mydatatype_t stack[maxstacksize];
int stackptr = 0;
#define push(d) stack[stackptr++] = d
#define pop stack[--stackptr]
#define topofstack stack[stackptr - 1]

error checking might idea :-)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > array push() + pop()?


arduino

Comments