Snippets Collections
import java.io.*;

class GFG {
    
    static void selectionSort(int arr[], int n){
        for(int i = 0; i < n; i++){
            int min_ind = i;
            
            for(int j = i + 1; j < n; j++){
                if(arr[j] < arr[min_ind]){
                    min_ind = j;
                }
            }
            
            int temp = arr[i];
            arr[i] = arr[min_ind];
            arr[min_ind] = temp;
        }
    }
    
	public static void main (String[] args) {
	    int a[] = {2, 1, 4, 3};
	    selectionSort(a, 4);
	    
	    for(int i = 0; i < 4; i++){
	        System.out.print(a[i] + " ");    // OUTPUT : 1 2 3 4
	    }
	}
}
#include <String.h>
#include <stdio.h>
int main() {
  // initializing the pointer string array
  char *names[] = {"tree", "bowl", "hat", "mice", "toon"};
  char *temp; // temporary variable for swaping the values
  int i, j, a;
  printf("The names are:\n");
  for (i = 0; i < 5; i++)
    printf("%s\n", names[i]);
  // arranging names in alphabetically using selection sort
  for (i = 0; i < 5; i++) {
    for (j = i + 1; j < 5; j++) {
      // compares the two string and returns an integer value
      // if the value of a is greater than 0 then swapping begins
      a = strcmp(names[i], names[j]);
      
      if (a > 0) {
        temp = names[i];
        names[i] = names[j];
        names[j] = temp;
      }
    }
  }
  printf("The arranged names are:\n");
  for (i = 0; i < 5; i++)
    printf("%s\n", names[i]);
  return 0;
}

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension