How to Search, Insert, and Delete in an Unsorted ArrayThis post discusses a code that performs search, insert, and delete actions on an unsorted array. Search Operation:With an unsorted array, the search operation can be accomplished by doing a linear traversal from the first to the final element. ![]() Programming execution of the search operation: C Programming Language: Output Element Found at Position: 4 C++ Program: Output Element Found at Position: 4 Java: Output Element Found at Position: 4
Insert Operation:1. Insert at the end:In an unsorted array, the insert operation is quicker than in a sorted array as we do not need to worry about the position at which the element is to be inserted. ![]() Programming execution of the insertion operation: C Programming Language: Output Before Insertion: 22 26 30 50 60 80 After Insertion: 22 26 30 50 60 80 34 C++ Program: Output Before Insertion: 22 26 30 50 60 80 After Insertion: 22 26 30 50 60 80 34 Java: Output Before Insertion: 22 26 30 50 60 80 After Insertion: 22 26 30 50 60 80 34
2. Insert at any pointInsert operations in an array can be performed at any point by moving elements to the right that are on the right side of the desired position. ![]() Programming execution of the insertion operation: C Programming Language: Output Before insertion : 1 3 5 7 4 After insertion : 1 3 5 9 7 4 C++ Program: Output Before insertion : 1 3 5 7 4 After insertion : 1 3 5 9 7 4 Java: Output Before insertion : 1 3 5 7 4 After insertion : 1 3 5 9 7 4
Delete Operation: The element to be deleted is found using a linear search, and then the delete operation is executed, followed by relocating the elements. ![]() Programming execution of the deletion operation: C Programming Language: Output Array before deletion 20 60 40 50 30 Array after deletion 20 60 50 30 C++ Program: Output Array before deletion 20 60 40 50 30 Array after deletion 20 60 50 30 Java: Output Array before deletion 20 60 40 50 30 Array after deletion 20 60 50 30
Next TopicCount Non-Leaf Nodes in a Binary Tree
|