Question: import edu.princeton.cs.algs4.Stack; import edu.princeton.cs.algs4.StdOut; // A data type representing a text editor buffer. public class Buffer { private Stack left; // chars left of cursor

 import edu.princeton.cs.algs4.Stack; import edu.princeton.cs.algs4.StdOut; // A data type representing a text

import edu.princeton.cs.algs4.Stack; import edu.princeton.cs.algs4.StdOut;

// A data type representing a text editor buffer. public class Buffer { private Stack left; // chars left of cursor private Stack right; // chars right of cursor

// Create an empty buffer. public Buffer() { ... }

// Insert c at the cursor position. public void insert(char c) { ... } // Delete and return the character at the cursor. public char delete() { ... }

// Move the cursor k positions to the left. public void left(int k) { ... }

// Move the cursor k positions to the right. public void right(int k) { ... }

// Return the number of characters in the buffer. public int size() { ... }

// Return a string representation of the buffer with a "|" character (not // part of the buffer) at the cursor position. public String toString() { ... } // Test client (DO NOT EDIT). public static void main(String[] args) { Buffer buf = new Buffer(); String s = "There is grandeur in this view of life, with its " + "several powers, having been originally breathed 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"; for (int i = 0; i Problem 4. (Tert Editor Buffer) Develop a data type Buffer for a buffer in a text editor that implements the following API method Buffer ( void insert (char c) char delete ) void left (int k) void right (int k) int size() description create an empty buffer insert c at the cursor position delete and return the character at the cursor move the cursor k positions to the left move the cursor k positions to the right number of characters in the buffer string representation of the buffer with a I' character (not part of the buffer) at the cursor position String toString) 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. $ 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 form s most beautiful and most wonderful have been, and are being, evolved Charles Darwin, The Origin of Species Problem 4. (Tert Editor Buffer) Develop a data type Buffer for a buffer in a text editor that implements the following API method Buffer ( void insert (char c) char delete ) void left (int k) void right (int k) int size() description create an empty buffer insert c at the cursor position delete and return the character at the cursor move the cursor k positions to the left move the cursor k positions to the right number of characters in the buffer string representation of the buffer with a I' character (not part of the buffer) at the cursor position String toString) 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. $ 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 form s most beautiful and most wonderful have been, and are being, evolved Charles Darwin, The Origin of Species

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!