Question

In: Computer Science

Bubble sort for 12, 2, 3, 21, 11, 10,8

Bubble sort for 12, 2, 3, 21, 11, 10,8

Solutions

Expert Solution

Babul sort:

Babul sort is sorting algorithm which is used to sort the elements

here for every element we compare with the preivious element if the element is smaller then we swap the element.

This process continues for every element untill the array is sorted

Code:

#include<stdio.h>
int main()
{
   int x[7]={12,2,3,21,11,10,8},i,j,tem,k;
   /*Declaring the variables*/
   for(i=0;i<7;i++)
   {
       printf("%d ",x[i]);
       /*Here we print the array elements*/
   }
   printf("\n");
   for(i=0;i<7;i++)
   {
       /*This loop iterated for every elements*/
       for(j=0;j<7-i-1;j++)
       {
           if(x[j]>x[j+1])
           {
               /*If the current element is greater than the next element
               Then we swap the elements*/
               tem=x[j];
               x[j]=x[j+1];
               x[j+1]=tem;
               for(k=0;k<7;k++)
               {
                   printf("%d ",x[k]);
                   /*Here we print the array after every swap*/
               }
               printf("\n");
           }
       }
   }
}

Output:

Here you can see how elements are sorted

Indentation:


Related Solutions

Bubble sort for 12, 2, 3, 21, 11, 10,8
Bubble sort for 12, 2, 3, 21, 11, 10,8
1. Insertion sort for 12, 2, 3, 21, 11, 10,8 2. Bubble sort for 12, 2,...
1. Insertion sort for 12, 2, 3, 21, 11, 10,8 2. Bubble sort for 12, 2, 3, 21, 11, 10,8 3. selection sort for 12, 2, 3, 21, 11, 10,8 analysis of algorithm
selection sort for 12, 2, 3, 21, 11, 10,8
selection sort for 12, 2, 3, 21, 11, 10,8
selection sort for 12, 2, 3, 21, 11, 10,8
selection sort for 12, 2, 3, 21, 11, 10,8
Analysis of Algorithims Bubble sort for 12, 2, 3, 21, 11, 10,8 Binary search for K=12...
Analysis of Algorithims Bubble sort for 12, 2, 3, 21, 11, 10,8 Binary search for K=12 in the array A={2, 3, 5, 7,11,15, 16,18,19} selection sort for 12, 2, 3, 21, 11, 10,8
Insertion sort for 12, 2, 3, 21, 11, 10,8 java lanuage
Insertion sort for 12, 2, 3, 21, 11, 10,8 java lanuage
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write...
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write the algorithm.
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT