{"id":25858,"date":"2021-12-16T09:20:30","date_gmt":"2021-12-16T03:50:30","guid":{"rendered":"https:\/\/python-programs.com\/?p=25858"},"modified":"2021-12-16T09:20:30","modified_gmt":"2021-12-16T03:50:30","slug":"python-program-for-brick-sort-algorithm","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-brick-sort-algorithm\/","title":{"rendered":"Python Program for Brick Sort Algorithm"},"content":{"rendered":"

Brick Sort Algorithm:<\/strong><\/p>\n

Brick Sort, commonly known as OddEven Sort, is a variant of Bubblesort. The sorting algorithm is separated into two stages: odd and even. The control loops until the array is sorted, ensuring that the even and odd stages are completed in each iteration.<\/p>\n

You may be wondering what these odd and even stages represent. We will only sort the elements existing at the odd indexes when the control executes the odd phase. Similarly, during the event phase execution, the control will only sort the elements at the even indexes.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [12, 9, 20, 2, 1, 5, -4]<\/pre>\n

Output:<\/strong><\/p>\n

The given list after sorting =  [-4, 1, 2, 5, 9, 12, 20]<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [4, -12, 56, 125, 0, -3, 7]<\/pre>\n

Output:<\/strong><\/p>\n

The given list after sorting = [-12, -3, 0, 4, 7, 56, 125]<\/pre>\n

Program for Brick Sort Algorithm in Python<\/h2>\n

 <\/p>\n

Method #1: Using Built-in Functions (Static Input)<\/h3>\n

Approach:<\/strong><\/p>\n