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
- AVL Tree | Set 2 (Deletion)
- Insert Operation in B-Tree
- Delete Operation in B-Tree
- Skip List | Set 3 (Searching and Deletion)
- Ternary Search Tree (Deletion)
- Find the number of different numbers in the array after applying the given operation q times
- Van Emde Boas Tree | Set 4 | Deletion
- Gap Buffer Data Structure
- Proto Van Emde Boas Trees | Set 4 | Deletion
- m-Way Search Tree | Set-2 | Insertion and Deletion
- Minimum cost of reducing Array by merging any adjacent elements repetitively
- Finding shortest path between any two nodes using Floyd Warshall Algorithm
- Isomorphism in N-ary Trees
- Sum of minimum element at each depth of a given non cyclic graph
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.