From the course: C# Hands-on Practice with Data-Structures

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Implement redo functionality with a stack

Implement redo functionality with a stack - C# Tutorial

From the course: C# Hands-on Practice with Data-Structures

Implement redo functionality with a stack

Let's use a stack to implement the redo functionality. In any undo and redo system, the redo functionality works by restoring the previous state that was undone. However, when new changes are made after an undo, such as saving new text or clearing text, the redo history becomes invalid. This means after saving or clearing text, we should also clear the redo stack. When an undo is performed, we should save the current state to the redo stack. This will allow us to redo the undo if needed. Let's modify the Undo method to push the current state onto the redo stack. Now for the Redo method. This should restore the state of the text before the last undo. We'll do this by popping off the last state from the redo stack and setting it to become the new current text. If the redo stack has items, we'll pop off the latest item and return true. Otherwise, we'll return false. We'll do this by popping off the last state from the redo stack and setting it to become the new current text. We'll also…

Contents