I am struggling to write the push and pop functions for a stack of arrays. I know how to write the code to push single items unto a stack and pop them out. Some have suggested that I use an array of arrays (two-dimensional array) to load the array of integers unto the stack. The array is of length 7 and there are 25 of these arrays that need to be pushed onto a stack and then popped out.
Usually, in my fillStack function, I read an element from a file and pass it to the push function. This time around, I read every element in the push function. I wrote the code below for the push function. It looks like an ordinary two dimensional array code. I am not sure if that will give me the results I want. When I began to consider how to revise the code to write the pop function, I realized I may be way off. I'll appreciate any assistance. Please include any important points I should take a note of when implementing a stack of arrays. Thanks.
void Stack::pushStack()
{
int i, elem;
if (!isFullStack())
{
for (i = 0; i < numRows; i++)
{
for (j = 0; j < numCols; j++)
{
infile >> elem;
stkArray[i][j] = elem;
}
//Just to check to make sure it's the right size/length
//of array is being loaded into the stack
outfile << "Stack row: " << stkArray << endl;
}
}
}//end pushStack