Skip to content

Commit 1969607

Browse files
committed
Insertion Sort
1 parent 74225a9 commit 1969607

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

Sorting/SelectionSort-Copy1.ipynb

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

0 commit comments

Comments
 (0)