Question: Exercise 4. (Text Editor Buffer) Implement a data type called Buffer to represent a buffer in a text editor. The data type must support the





Exercise 4. (Text Editor Buffer) Implement a data type called Buffer to represent a buffer in a text editor. The data type must support the following API: E Buffer Buffer() void insert (charc) char delete() void left(int k) creates an empty buffer inserts c at the cursor position deletes and returns the character immediately ahead of the cursor moves the cursor k positions to the left moves the cursor k positions to the right returns the number of characters in this buffer returns a string representation of this buffer with the "T" character (not part of the buffer) at the cursor position void right(int k) int size() String toString() >- */workspace/project2 $ java Buffer | There is grandeur in this view of life, with its several powers , having been originally breathed by the Creator into a few forms or into one; and that, whilst this planet has gone cycling on according to the fixed law of gravity, from so simple a beginning endless forms most beautiful and most wonderful have been, and are being, evolved. Charles Darwin, The Origin of Species Hint: Use two stacks left and right to store the characters to the left and right of the cursor, with the characters on top of the stacks being the ones immediately to its left and right. C Buffer.java import dsa. LinkedStack; import stdlib.Stdout; // A data type to represent a text editor buffer. public class Buffer { protected LinkedStack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
