# Write ac program for bubble sorting

By the above recursive argument, this second largest array will then reach the last position in the remaining array [1, 2, 3, 4]. If first element is greater than the second, then swapped will be performed otherwise not.

For example, if we have total of 10 elements in the arraythen we have to perform swapping 10 times as shown in the program given here. C program to test if a number is a power of 2 C program to sort array using bubble sort algorithm Sorting data either in ascending or descending order is the important computing application that can be achieved by various ways.

So, at the end of the first pass, the largest element will always reach its correct position. Sorting forms a great case study for those who want to learn Data Structures and Algorithms. In function, we have used same technique as discussed above, that is comparing each consecutive elements from starting to ending.

Basically, we need to find a way to sort this array so that the final array obtained is [1, 2, 3, 4, 5]. View all posts by Aman Goel Related Posts. Therefore, it will take a lot of iterations for the algorithm to complete.

### Insertion sort program in c

Finally, the array gets sorted. Now again, 4, 3 is incorrect so we do another swap and get [1, 2, 3, 4, 5]. As a simple example, the numbers 1, 2, 3, 4, 5 are sorted in ascending order. For instance, during our school days, we are told to stand in the queue based on our heights. We repeat this until the array is sorted. This is undesirable. In function, we have used same technique as discussed above, that is comparing each consecutive elements from starting to ending. As an example, we are given an array of integers: [5, 1, 4, 2, 3]. These data arrangements give easier access to data for future use for ex. So, at the end of the first pass, the largest element will always reach its correct position.

Now again, 4, 3 is incorrect so we do another swap and get [1, 2, 3, 4, 5].

Rated 10/10 based on 65 review