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
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:
- can’t use the buffer before creating it.
- can’t delete a character from an empty buffer.
- 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.
- 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.