Showing posts with label Sort. Show all posts
Showing posts with label Sort. Show all posts

Wednesday, August 7, 2013

Insertion sort


Program      :  Implement sorting methods using functions Insertion sort
Created By :  JABIR PATHAN

#include<stdio.h>
#include<conio.h>
void main()
 {
    int i,j,arr[30],n,temp,ch,k,d;
    clrscr();
    printf("\n\nHow many elements you want to enter in array==>");
    scanf("%d",&n);
    printf("\n\nEnter the elements==>\n");
    for(i=0;i<n;i++)
          scanf("%d",&arr[i]);
    printf("\naccepted elements are==>\n");
    for(i=0;i<n;i++)
         printf("\narr[%d]=%d",i,arr[i]);
    for(i=1;i<n;i++)
    {
      temp=arr[i];
      for(j=i-1;j>=0&&arr[j]>temp;j--)
       {
        arr[j+1]=arr[j];
        arr[j]=temp;  
      }
     printf("\n\npasses=%d",i);
     for(k=0;k<n;k++)
      {
       printf("\t%d",arr[k]);
      }
    }
   printf("\n\nsorted Elements Are==>\n ");
   for(i=0;i<n;i++)
   {
     printf("\narr[%d]=%d",i,arr[i]);
   }
  getch();
}
Click here to Download this Zip file
Password - JP

Monday, October 3, 2011

Bubble Sort

Program       :  Write a program in C to Sort N Integer Using Bubble Sort
Created By  :  JABIR PATHAN

#include<stdio.h>
#include<conio.h>
void main()
{
   int arr[100],i,j,temp,n;
   clrscr();
   printf("Enter the How many Elements you want to enter in array==>");
   scanf("%d",&n);
   for(i=0;i<=n-1;i++)
   {
     printf("\nEnter elements for arr[%d]=",i);
     scanf("%d",&arr[i]);
   }
   printf("\n\nAccepted Array Elements Are==>\n ");
   for(i=0;i<=n-1;i++)
    {
      printf("\n arr[%d]=%d",i,arr[i]);
    }

   for(i=0;i<=n-1;i++)
    {
      for(j=0;j<=n-1;j++)
       {
          if(arr[j]>arr[i])
           {
              temp=arr[i];
              arr[i]=arr[j];
              arr[j]=temp;
           }
      }
  }
 printf("\n\n\nThe content of an array in an ascending order are==>\n");

 for(i=0;i<=n-1;i++)
   {
     printf("\narr[%d]=%d",i,arr[i]);
   }
  getch();
}