Write a C++ program to insert ordelete characters in a buffer. You need to develop an abstract datatype for a buffer in the text editor program that implements thefollowing operations using linked list. Implement thebuffer as a singly linked list of char

匿名用户 最后更新于 2021-11-29 17:10 计算机类Computing

Write a C++ program to insert ordelete characters in a buffer. You need to develop an abstract datatype for a buffer in the text editor program that implements thefollowing operations using linked list. Implement thebuffer as a singly linked list of char in C++

  • Create an emptybuffer createBuffer()
  • Insert a character at the cursor position insert(char c)
  • Get the character at the cursor position char get()
  • Delete and return the character at the cursor chardelete()
  • Move the cursor k position to the left void left (int k)
  • Move the cursor k positions to the right void right(int k)
  • Return the number of characters in the buffer int size()
  • Also Implement the following constraints in the bufferoperations:
  1. can’t use the buffer before creating it.
  2. can’t delete a character from an empty buffer.
  3. move the cursor k positions to the right where k <= n and nis the number of characters-in the buffer. If k >= n then thecursor moves to the last character in the buffer.
  4. move the cursor k positions to the left where current position– k < 0 returns the cursor to 0 position. For example, ifcurrent position is 5 and k = 10 then 5-10 = -5 <0 then cursorwill be in position 0.

已邀请: