I'm working on a bunch of stuff with arrays. At the moment I'm trying to come up with with an insert function that allows me to put as many elements as I want into an array, only keeping the five recent most elements.
So I guess what I want to do is drop the first element and push the rest back one position in the array. Will this do the job?
if ( Size < MAX_SIZE ) Data[ Size++ ] = NewData; // Only the five recentmost numbers are subject to testing // so, drop the first and pushback the rest, and insert // newest element into spot five. if ( Size >= MAX_SIZE ) for ( Index = 0 ; Index < MAX_SIZE - 1 ; ++Index ) Data[ Index ] = Data[ Index + 1 ]; Data[ MAX_SIZE - 1 ] = NewData;