#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    15
    Rep Power
    0

    Problem in Recurssion


    Hello Friends,
    I have written a program for Selection sort. I want to write the same program in Recursive way. Plz help me in it.
    Code:
    #include "stdafx.h"
    #include<stdio.h>
    #include<conio.h>
    
    int main()
    {
    	int a[10];
    	int i ,j=0,k=0;
    	int temp=0;
    
    	printf("Enter the element for Selection sort ");	
    	for(i=0;i<=9;i++)
    		{
    		
    	    scanf("%d",&a[i]);
    		}
    
    		for(i=0;i<=8;i++,j++)
    		{
    			for(k=j;k<=8;)
    			{
    				if(a[j]<a[k+1])
    					k++;
    			
    			   else
    			   {
    				temp=a[j];
    				a[j]=a[k+1];
    				a[k+1]=temp;
    			   }
    			}
    		}
    			for(i=0;i<=9;i++)
    			{ 
    				printf("\nSorted Elements are :%d",a[i]);
    			}
    			_getch();
    			return 0;
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    San Francisco Bay
    Posts
    1,939
    Rep Power
    1313
    1. Find the smallest item in the array.
    2. Swap it into the first position.
    3. Recurse, omitting the first position.

IMN logo majestic logo threadwatch logo seochat tools logo