# C Program to Sort an Array Using Insertion Sort

Sorting is a procedure in which the given elements are arranged in ascending or descending order. For example if the elements of an array are –

5, 11, 15, 8, 7, 54, 63, 44

After sorting these elements in ascending order, the elements would be –

5, 7, 8, 11, 15, 44, 54, 63

What is Insertion Sort is :

Insertion sort proceeds by inserting each element at the proper place in a sorted list. This is the same technique used by card players for arranging cards. When they receive a card, they place it in the appropriate place among the cards that they have already arranged.

We will consider our list to be divided into two parts – sorted and unsorted. Initially the sorted part contains only the first element of the list and unsorted part contains the rest of the elements. In each pass, the first element from the unsorted part is taken and inserted into the sorted part at appropriate place. If there are n elements in the list, then after n-1 passes the unsorted part disappears and our whole list becomes sorted. Let’s see the c program to sort an array using insertion sort.

# C Program to Search for an Element in an Array Using Binary Search

There is a condition for performing binary search, the prerequisite for binary search is that the array should be sorted. Firstly we compare the item to be search with the middle element of the array, if the the item is found the search is successful otherwise the array is divided into two halves, first half contains all the elements to the left of the middle element and the other one consists of all the elements to the right side of the middle element. Since the array is sorted, all the element in the left half will be smaller than the middle element and greater than the middle element in the right half. If the item to be search is less than the middle element, it will be search in left half otherwise it will be search in the right half (if it is greater then the middle element). Let’s now see the c program to search for an element in an array using binary search.

# C Program to Search an Element in an Array Using Linear or Sequential Search

Before making the C program to search an element in an array using linear search, first understand what linear search means. Sequential search or Linear search is performed in linear way i.e. it starts from the beginning of the list and continues till we find the item or reach the end of list. The item to be searched is compared with each element of the list one by one, starting from the first element.

Let’s See The Program ►►
Continue reading C Program to Search an Element in an Array Using Linear or Sequential Search

# C Program to Find The Second Largest Element Of An Array

Arrays provide the great way to store the values. And plays ah important role in C. I made many programs on arrays. And as we know array elements are always store in Contiguous Memory Location so it’s always great to combine array with pointers that makes accessing and manipulating array more handy.

You might made the program to find the largest element of array. I come with the code to find the second largest element and also the use of macros in the program to run it more faster and avoid re-righting the same line again and again.

Lets Have ah Look at the Program ►► Continue reading C Program to Find The Second Largest Element Of An Array