Consider the following method body which deletes a number from array: void deleteNum(int n) { int i, j, found = 0; //This method deleted a number from an array for (i = 0; i < counter; i++) { if (NumAry[i] == n) { for (j = i; j < (counter - 1); j++) NumAry[j] = NumAry[j + 1]; found = 1; i--; counter--; } } if (found == 0) cout << "\nElement doesn't found in the Array!"; else { cout << "\nElement Deleted Successfully!"; } } I want additional functionality in above method that when a number is deleted it should move that number to stack with the number itself and its position in array. Then the method shows menu to user if he wants to undo the deleted number and pop the number from stack and place it from where it is deleted from array. Use arrays as stack and dont use pointers please.
Consider the following method body which deletes a number from array:
void deleteNum(int n) {
int i, j, found = 0; //This method deleted a number from an array
for (i = 0; i < counter; i++) {
if (NumAry[i] == n) {
for (j = i; j < (counter - 1); j++)
NumAry[j] = NumAry[j + 1];
found = 1;
i--;
counter--;
}
}
if (found == 0)
cout << "\nElement doesn't found in the Array!";
else {
cout << "\nElement Deleted Successfully!";
}
}
I want additional functionality in above method that when a number is deleted it should move that number to stack with the number itself and its position in array. Then the method shows menu to user if he wants to undo the deleted number and pop the number from stack and place it from where it is deleted from array.
Use arrays as stack and dont use pointers please.
Step by step
Solved in 2 steps with 2 images