In this post we will see how to implement the bubble sort algorithm in java with a sample program.
Lets say there are N elements in the array to be sorted and the bubble sorting takes place by
When we run the above program,we will get this output
Above output will show the array elements position at the end of each iteration and how the elements in the arrays were swapped.
Lets say there are N elements in the array to be sorted and the bubble sorting takes place by
- Comparing the adjacent elements in the array and swap its corresponding position if found greater.
- Above step will be iterated upto the maximum of N -1 iteration until the array is fully sorted.
When we run the above program,we will get this output
Above output will show the array elements position at the end of each iteration and how the elements in the arrays were swapped.
No comments:
Post a Comment