1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <stdio.h> #include <conio.h> void selection_sort(int arr[],int n){ // function to sort with selection algorithm int i,j,smallest,position,start=1,temp; for (i=0;i<n;i++) { smallest=arr[i]; // smallest number and position is initialized position=i; for(j=start;j<n;j++) { if(smallest>arr[j]) { // check if any other number is smaller smallest=arr[j]; position=j; } } if(arr[i]!=smallest) { // if smallest value changed than swap temp=arr[i]; arr[i]=smallest; arr[position]=temp; } start=start+1; } } void print_array(int arr[],int n) { //function to print a n size array int i; for(i=0;i<n;i++) { printf("%d",arr[i]); } } void main() { int i,arr[20],n; clrscr(); printf("Enter the no of elements "); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n Enter the element %d :",i+1); scanf("%d",&arr[i]); } selection_sort(arr,n); print_array(arr,n); getch(); } |
Java
Java Applet Of Moving Plane
“applet” class [crayon-5a2bba9d52195504229521/] HTML File [crayon-5a2bba9d521a0728279431/] How to Run After compilation you can use “appletviewer” to run your applet. appletviewer xyz.html