Skip to content

Commit 79122ab

Browse files
committed
Merge Sort copy added
1 parent 2e1f131 commit 79122ab

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

Sorting/InsertionSort-Copy1.ipynb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 3,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdin",
10+
"output_type": "stream",
11+
"text": [
12+
"Enter N 4\n",
13+
" 3\n",
14+
" 2\n",
15+
" 5\n",
16+
" 6\n"
17+
]
18+
},
19+
{
20+
"name": "stdout",
21+
"output_type": "stream",
22+
"text": [
23+
"Sorted array is:\n",
24+
"2\n",
25+
"3\n",
26+
"5\n",
27+
"6\n"
28+
]
29+
}
30+
],
31+
"source": [
32+
"def Selection(arr):\n",
33+
" n = len(arr)\n",
34+
"\n",
35+
" for i in range(1, len(arr)): \n",
36+
" key = arr[i] \n",
37+
" j = i-1\n",
38+
" while j >=0 and key < arr[j] : \n",
39+
" arr[j+1] = arr[j] \n",
40+
" j -= 1\n",
41+
" arr[j+1] = key \n",
42+
" \n",
43+
"\n",
44+
"arr = []\n",
45+
"n=int(input(\"Enter N\"))\n",
46+
"for x in range(n):\n",
47+
" arr.append(int(input()))\n",
48+
"\n",
49+
"Selection(arr)\n",
50+
" \n",
51+
"print (\"Sorted array is:\")\n",
52+
"for i in range(len(arr)):\n",
53+
" print (arr[i]),"
54+
]
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "Python 3",
60+
"language": "python",
61+
"name": "python3"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 3
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython3",
73+
"version": "3.7.4"
74+
}
75+
},
76+
"nbformat": 4,
77+
"nbformat_minor": 4
78+
}

0 commit comments

Comments
 (0)