Shaker Sort Data Structure C Program

This Program is for Shaker Sort. This is part of Mumbai University MCA Colleges Data Structures C program.

#include<stdio.h>
#include<conio.h>
void main()
{
          int arr[10]={100,25,88,13,76,31,45,68,94,53};
          int current,sorted,walker1,walker2,temp,i;
          clrscr();
          current=0;
          sorted=0;
          printf("The original array is:\n----------------------\n");
          for(i=0;i<10;i++)
          printf("%d ",arr[i]);
          while(current<3 && sorted==0)
          {
                   walker1=9;
                   walker2=current;
                   sorted=1;

                   while(walker1>current)
                   {
                             if(arr[walker1]<arr[walker1-1])
                             //Least value bubbles to the beginning of the array
                             {
                                      sorted=0;
                                      temp=arr[walker1];
                                      arr[walker1]=arr[walker1-1];
                                      arr[walker1-1]=temp;
                             }
                             if(arr[walker2]>arr[walker2+1])
                             //Greatest value bubble to the end of the array
                             {
                                      sorted=0;
                                      temp=arr[walker2];
                                      arr[walker2]=arr[walker2+1];
                                      arr[walker2+1]=temp;
                             }
                             walker2++;
                             walker1--;
                   }
                   current++;
                   printf("\n\n\n\nAfter %d pass of Shaker Sort:\n\n",current);
                   for(i=0;i<10;i++)
                             printf("%d ",arr[i]);
          }
          getch();
}



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment