Happy New Year 2014

POLL OF THE DAY
How do you back up your personal data?






Want to create a new poll now?
(Login Required)

How do you back up your personal data?

OptionsVotes% 
USB thumb drive 0 0.00
External hard drive 6 66.70
Optical disc 0 0.00
Memory card 0 0.00
Online backup service 2 22.20
Multiple methods 1 11.10
Network-attached storage device 0 0.00

Total Responses: 9

Not scientifically valid. Results are updated every 15 minutes.

 

Bubble sort in C-Language

Author: Renuka Email: ********
Last Updated: 8/6/2010 8:30:00 PM Views:
25718
Level: Intermediate Downloads: 0
   

Introduction

Sorting is arranging the given list in ascending/descending order, with respect to a given key field. This list can be number of records, with each record having many fields.

Types of sorting

  • Exchange/Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Quick/Partition Exchange Sort
  • Merge/2-Way Merge Sort

Exchange/Bubble Sort : It uses simple algorithm. It sors by comparing each pair of adjusent items and swaping them in the order .This will be repeated until no swaps are needed. The algorithm got its name from the way smaller elements "bubble" to the top of the list.

It is not that much efficient, when a list is having more than a few elements. Among simple sorting algorithms, algorithms like insertion sort are usually considered as more efficient.
Bubble sort is little slower compared to other sorting techniques but it is easy because it deals with only two elements at a time.

An example to bubble sort is given below.

    #include <stdio.h>
    void main()        
    {
        int a[10]={34,2,56,78,34,5,76,10,47,29};  //initializing array of elements
        int n=10;
        int i,j,temp;
        for(i=0;i<10;i++)            //for loop to select each element in the array
        { 
            for(j=0;j<n-i;j++)      //for loop to swap elements after comparing
            {
                if(a[j]>a[j+1])
                {
                    temp=a[j];       //swaping
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }            
            }                
        }
        for(i=0;i<n;i++)           //for loop to print sorted elements
                {
                    printf("%d \n",a[i]);
                }
    }
    
Comments
rep:Bubble sort in C-Language
Pls explain me bubble sort with an example not by programming language.
rep:Bubble sort in C-Language
why it is not running in my "c-free5" application ???
rep:Bubble sort in C-Language
Exactly what i needed. I'll try it. I hope it will work for a beginner like me. Thanks.
rep:Bubble sort in C-Language
thanks for cleraring my doubts
rep:Bubble sort in C-Language
thank you for help in c language....
rep:Bubble sort in C-Language
thanks a lot
rep:Bubble sort in C-Language
enquary
Post your comments:

Name :    
Email :      
Subject :  
Message :    
Type the word :    
 
 
 


Contact us

You might also like this!