IIT Bombay Data Structures and Algorithms Prof Ajit

IIT Bombay Data Structures and Algorithms Prof. Ajit A. Diwan Prof. Ganesh Ramakrishnan Prof. Deepak B. Phatak Department of Computer Science and Engineering IIT Bombay Session: Text Editor using 2 Stacks (Program) Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 1

Functions IIT Bombay 1. 2. 3. 4. 5. 6. 7. 8. 9. insert. Word insert. Character delete. Character back. Space. Character move. Cursor move. Left move. Right replace examine. Top Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 2

Program IIT Bombay Class ‘text. Editor’ with member variables and its member functions class text. Editor { private: stack<char> left. Stack; //Left stack<char> right. Stack; //Right stack public: void insert. Word(char word[]); void insert. Character(character); bool delete. Character(); bool back. Space. Character(); void move. Cursor(int position); void move. Left(int position); void move. Right(int position); void find. And. Replace. Char(char find. What, char replace. With); void examine. Top(); }; //End of class Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 3

Program IIT Bombay void text. Editor: : examine. Top(){ if(left. Stack. empty()) cout << "left. Stack: emptyt"; else cout << "left. Stack: " << left. Stack. top() << ", " << left. Stack. size() << "tt"; if(right. Stack. empty()) cout << "right. Stack: emptyn"; else cout << "right. Stack: " << right. Stack. top() << ", " << right. Stack. size() << endl; } //End of function Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 4