Selection sort

#include<stdio.h>

void selsort(int a[],int n);

int main()

{

  int a[10],n,i;

  clrscr();

  printf("\n enter no.of elements:");

  scanf("%d",&n);

  printf("\n enter %d elements:",n);

  for(i=0;i<n;i++)

  {

     scanf("%d",&a[i]);

  }

  selsort(a,n);

  return 0;

}

  void selsort(int a[],int n)

      {

  int i,j,k,pos,t;

  for(i=0;i<n-1;i++)

    {

       pos=i;

       for(j=i+1;j<n;j++)

{

    if(a[j]<a[pos])

    pos=j;

}

       if(i!=pos)

   {

      t=a[i];

      a[i]=a[pos];

      a[pos]=t;

   }

    printf("\n after pass %d :" ,i+1);

    for(k=0;k<n;k++)

{

   printf("%d\t ",a[k]);

}

    }

     }

Comments

Popular posts from this blog

Create a Binary Search Tree of integers and perform the following operations (i)insert (ii) delete (iii). Search (iv) traversals (pre-order, in-order, post-order) BST

Creation Of DLL

Develop non-recursive functions to perform search for a Key value in a given list using (i) Binary Search Non Recursive