#include <iostream>
#include <stack>
#include <string>
using namespace std;
class TextEditor {
private:
string document;
stack<string> undoStack;
stack<string> redoStack;
public:
// Make a new change to the document
void makeChange(const string& newText) {
[Link](document); // Save current state before changing
document = newText;
while (![Link]()) [Link](); // Clear redo stack after new change
// Undo the last change
void undoAction() {
if ([Link]()) {
cout << "No changes to undo.\n";
return;
[Link](document); // Save current state to redo stack
document = [Link](); // Revert to previous state
[Link]();
// Redo the last undone action
void redoAction() {
if ([Link]()) {
cout << "No actions to redo.\n";
return;
[Link](document); // Save current state to undo stack
document = [Link](); // Reapply the undone state
[Link]();
// Display the current document state
void displayDocumentState() const {
cout << "Current Document: \"" << document << "\"\n";
};
int main() {
TextEditor editor;
int choice;
string text;
while (true) {
cout << "\n--- Text Editor ---\n";
cout << "1. Make a Change\n2. Undo Action\n3. Redo Action\n4. Display Document State\n5.
Exit\n";
cout << "Enter your choice: ";
cin >> choice;
[Link](); // clear newline from buffer
switch (choice) {
case 1:
cout << "Enter new text: ";
getline(cin, text);
[Link](text);
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
return 0;
default:
cout << "Invalid choice!\n";