-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertioncode.html
58 lines (52 loc) · 1.3 KB
/
insertioncode.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<style>
body {padding-top:50px ; margin-top: auto; margin-left: 30px;background-color:#0c7b93;color: white}
h1 {text-align: center; color: black;}
</style>
</head>
<body>
<h1>INSERTION SORT
<div class="">
<button onclick="location.href='index.html'">Go to home page</button> <br /><br />
</div></h1>
#include <stdio.h><br />
using namespace std;<br />
void insertionSort(int A[],int n)<br />
{<br />
for(int i=1;i<n;i++)<br />
{<br />
int j=i-1;<br />
int key=A[i];<br />
while(j>=0 && A[j]>key)<br />
{<br />
A[j+1]=A[j];<br />
j--;<br />
}<br />
A[j+1]=key;<br />
}<br />
}<br />
int main()<br />
{<br />
int n;<br />
cout<<"Enter number of elements\n";<br />
cin>>n;<br />
int A[n];<br />
cout<<"Enter elements one one\n";<br />
for(int i=0;i<n;i++)<br />
{<br />
cin>>A[i];<br />
}
<br />
insertionSort(A,n);<br />
cout<<"Sorted Array is\n";<br />
for(int i=0;i< n ;i++)<br />
{<br />
cout<< A[i]<<" ";<br />
}<br />
}<br />
</body>
</html>