# Thread: What is bubble sort in data structure

1. Member
Join Date
Dec 2010
Posts
10

## What is bubble sort in data structure

Hello friends, I am aware of the process sorting and some of its type not all. I wanted to know the bubble sorting. I have no ideas about it. I also wanted the code for bubble sorting. I have tried it but I was unable to get the appropriate output. If anyone is having any clue or idea about this query then please let me know so that my concepts are cleared and I can get the appropriate output.

2. Member
Join Date
Apr 2009
Posts
570

## Re: What is bubble sort in data structure

In this method 0th element is compared with the 1st element. If it is found to be greater than the 1st element then they are interchanged .Then the first element is compared with the 2nd element, if it is found to be greater, then they are interchanged. In this way all the elements are compared with the next element and interchanged if required. This is the first iteration and on completing this iteration the last element gets placed at the last position.

3. Member
Join Date
May 2009
Posts
529

## Re: What is bubble sort in data structure

Similarly in the second iteration the comparisons are made till the last but one element and this time the second largest element gets placed at the second last position in the list. As a result after all the iteration the list becomes a sorted list. You must make sure that the list is sorted and compared properly after the iteration process is over. Many of them mistakes while comparing when iteration is done.

4. Member
Join Date
May 2009
Posts
513

## Re: What is bubble sort in data structure

Code:
Declare array AA
store elements in to array AA

Repeat for i= 0 to i<=3                        // for passess
Repeat for j=0 to j<=3-i                    // for comparision
check  if AA[j] >AA[j+1]             // for exchanging largest number
int  k = AA[j]
AA[j]=AA[j+1]
AA[j+1] =k
increment j by 1
repeat step 6 to 9
End of loop
increment i by 1
repeat step  5 to 11
end of loop

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•