Skip to main content

Posts

Showing posts from 2019

Sorting Operations in Design Analysis and Algorithm

/* Implementing  sorting in a C Program  * Written by: Riddhi Lalakiya.   */ Sorting Algorithms in C 1.BubbleSort : 1. Algorithm : begin BubbleSort(list)    for all elements of list       if list[i] > list[i+1]          swap(list[i], list[i+1])       end if    end for        return list     end BubbleSort 2. Pseudocode : procedure bubbleSort( list : array of items )    loop = list.count;        for i = 0 to loop-1 do:       swapped = false       for j = 0 to loop-1 do:                 /* compare the adjacent elements */             if list[j] > list[j+1] then             /* swap them */             swap( list[j], list[j+1] )               swapped = true          end if                 end for              /*if no number was swapped that means        array is sorted now, break the loop.*/              if(not swapped) then          break       end if           end for