Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Bidirectional Bubble Sort in Sorting of Data structures & Algorithm
3754 Views
JAVA Example
public void bidirectionalBubbleSort()
{
   int left = 0, right = a.length-1;
   while (left < right)
   {
      for (int pos = left; pos < right; pos++)
      {
         if (a[pos] > a[pos+1])
            swap(pos, pos+1);
      }
      right--;


      for (int pos = right; pos > left; pos--)
      {
         if (a[pos] < a[pos-1])
           swap(pos, pos-1);
      }
      left++;
   }
}
Working Style 
1. First moves highest bubble to top
2. From n - 1 to 0 small number moves to down
3. Left to right way moves highest no to second right
4. Moves second least no to second down
5. Likewise
Next Topics
Next lessons of current book.
Previous Topics
Previous lessons of current book.
Best Lessons of "Data structures & Algorithm"
Top lessons which are viewed more times.
Sub Lessons
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details