We have discussed Gap buffer and insert operations. In this post, delete operation is discussed. When we want to delete a character these three cases may arise.
- Characters to be deleted is at cursor position: Let’s assume we want to delete “FOR” from “FORGEEKS”, since the cursor (gap_left) is at desired position the character is deleted i.e. the gap takes the character inside itself and the character gets deleted.
- Characters to be deleted is left of cursor position: For this case since “FOR” is left to the cursor position we must reach to the desired position by using left() as in previous article. Now, we can delete “FOR” as in case 1.
- Characters to be deleted is right of cursor position: For this case also the cursor position is right to the desired position we must reach there by using right() as in previous article. Now, we can delete “FOR” as in case 1.
Implementing Gap Buffer with Deletion
Initializing the gap buffer with size 10 _ _ _ _ _ _ _ _ _ _ Inserting a string to buffer: GEEKSGEEKS Output: G E E K S G E E K S _ _ _ _ _ _ _ _ _ _ Inserting a string to buffer: FOR Output: G E E K S F O R _ _ _ _ _ _ _ G E E K S Deleting character at position 5 Output: G E E K S _ _ _ _ _ _ _ _ O R G E E K S Deleting character at position 6 Output: G E E K S O _ _ _ _ _ _ _ _ _ G E E K S Deleting character at position 5 Output: G E E K S _ _ _ _ _ _ _ _ _ _ G E E K S Inserting a string to buffer: HELLO Output: H E L L O _ _ _ _ _ G E E K S G E E K S
- Gap Buffer Data Structure
- AVL Tree | Set 2 (Deletion)
- Skip List | Set 3 (Searching and Deletion)
- Ternary Search Tree (Deletion)
- Van Emde Boas Tree | Set 4 | Deletion
- Proto Van Emde Boas Trees | Set 4 | Deletion
- m-Way Search Tree | Set-2 | Insertion and Deletion
- Insert Operation in B-Tree
- Delete Operation in B-Tree
- Find the number of different numbers in the array after applying the given operation q times
- Generate original permutation from given array of inversions
- Comparision between Tarjan's and Kosaraju's Algorithm
- Convert a Generic Tree(N-array Tree) to Binary Tree
- Pair of strings having longest common prefix of maximum length in given array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.