helppp

how do you write a code regarding the push/pop data array display except the function undeletes the elements of an array, meaning the most recently removed value is restored or undeleted.... I have the code to insert

1
2
3
4
5
6
7
8
9
10
if (!isFull())
	{
		data[++count] = value;		
		cout << setw(4) << value << " has been inserted in data[" << count << "]." << endl;
	}
	else {
		cout << "Attempts to insert a value into a full container; program is terminated!";
		exit (1);
	}


and to display
1
2
3
4
5
6
7
8
9
10
cout << "The 'container' contains the following " << count + 1 << " value(s):\n";
	if (count == -1)
		cout << "*** data array is empty!" << endl;
	else
	{
		for (int i = 0; i <= count; i++)
			cout << data[i] << '\t';
		cout << endl;
	}
}

and to remove
1
2
3
4
5
6
7
if( isEmpty( ) ) // the stack is empty
{
cout << endl << “Stack is empty” << endl;
exit( 1 );
}
value = data[ count ];
count-- ;}

but i don't know the code to unremove.
Please help, Thanks!
Last edited on
Cant you just save the value before removing it, and then if you want to undelete it you can just put it back in?
bump
@tarikneaj how would i be able to save the value before removing it ?
Just create a variable called like lastSaver or whatever, and let this variable always contain the last removed element.

Basically just before calling remove on whatever you're removing. Save it.
Topic archived. No new replies allowed.