Apply undo,redo operations on string pool. please friends help me to get its answer.

Recommended Answers

All 5 Replies

Well, you just treat the string with state. You must have 2 dynamic collection variables (possibly ArrayList) to handle this task. When something is changed, add to undo. When something is undo, pop the item out from the undo list and add it to redo list (and vice versa). If the list is empty, do nothing.

as Taywin says, you'll need an entire structure to do this. you can't do such on a String itself, since a String is immutable

I agree have 2 stacks. E.g. do and redo.

doOperation(String str) {
do.add(str);
}

undo() {
String s= do.pop();
redo.add(s);
}

redo() {
String s= redo.pop();
do.add(s);
}

I am a beginner. Please can anyone elaborate it for me.

you switch items from two listing (stack).

undo means reversing the last thing you did. so stack is the most appropriate for this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.