Skip to content

Data Structures and Algorithms from around the World !

Notifications You must be signed in to change notification settings

jatinchauhann/DataStructures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

DataStructures

Data Structures and Algorithms from around the World

INDEX

Sorting Algorithms

  1. Insertion Sort

CODE (FUNCTIONS)

  1. Insertion Sort
public static void insertionSort(int[] arr, int n) {
		for (int j = 2; j <= n; j++) {
			int key = arr[j]; //temporarily storing the target element since it can be relocated further 
			int i = j - 1;
			while (i > 0 && arr[i] > key) {
				//running a loop, to find the correct position of the element 
				arr[i + 1] = arr[i];
				i = i - 1;
			}
			arr[i + 1] = key;
		}
	}

About

Data Structures and Algorithms from around the World !

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages