Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

When there was controversy, was it clear who had the final say?

Answered: 1 week ago