Skip to content

Commit 3348507

Browse files
Add files via upload
0 parents  commit 3348507

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

ArrayDataStructureAlgorithm.ipynb

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": []
7+
},
8+
"kernelspec": {
9+
"name": "python3",
10+
"display_name": "Python 3"
11+
},
12+
"language_info": {
13+
"name": "python"
14+
}
15+
},
16+
"cells": [
17+
{
18+
"cell_type": "code",
19+
"source": [
20+
"!pip install Arrays"
21+
],
22+
"metadata": {
23+
"id": "zUhXxXPGTA71",
24+
"colab": {
25+
"base_uri": "https://localhost:8080/"
26+
},
27+
"outputId": "c97b4e00-679d-4480-8477-05a1251c8c9c",
28+
"collapsed": true
29+
},
30+
"execution_count": null,
31+
"outputs": [
32+
{
33+
"output_type": "stream",
34+
"name": "stdout",
35+
"text": [
36+
"Collecting Arrays\n",
37+
" Downloading Arrays-0.0.5-py3-none-any.whl.metadata (1.2 kB)\n",
38+
"Downloading Arrays-0.0.5-py3-none-any.whl (2.2 kB)\n",
39+
"Installing collected packages: Arrays\n",
40+
"Successfully installed Arrays-0.0.5\n"
41+
]
42+
}
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"source": [
48+
"import Arrays"
49+
],
50+
"metadata": {
51+
"id": "a7Re_vqJXTU6"
52+
},
53+
"execution_count": null,
54+
"outputs": []
55+
},
56+
{
57+
"cell_type": "code",
58+
"source": [
59+
"def ReversingArray(start , end , array):\n",
60+
" while (start < end):\n",
61+
" array[start] , array[end] = array[end] , array[start]\n",
62+
" start += 1\n",
63+
" end -= 1\n",
64+
" return array"
65+
],
66+
"metadata": {
67+
"id": "8fNH-T8bXcso"
68+
},
69+
"execution_count": null,
70+
"outputs": []
71+
},
72+
{
73+
"cell_type": "code",
74+
"source": [
75+
"if __name__ == \"__main__\":\n",
76+
" array = [1,2,3,4,5,6]\n",
77+
" print('Old Array: ', array)\n",
78+
" print('New Array: ', end = ' ')\n",
79+
" print(ReversingArray(0,5,array))\n"
80+
],
81+
"metadata": {
82+
"colab": {
83+
"base_uri": "https://localhost:8080/"
84+
},
85+
"collapsed": true,
86+
"id": "cHJr__rkXzto",
87+
"outputId": "45668ade-f40f-4133-dbe3-90f8a1dc9c3a"
88+
},
89+
"execution_count": null,
90+
"outputs": [
91+
{
92+
"output_type": "stream",
93+
"name": "stdout",
94+
"text": [
95+
"Old Array: [1, 2, 3, 4, 5, 6]\n",
96+
"New Array: [6, 2, 3, 4, 5, 1]\n"
97+
]
98+
}
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"source": [
104+
"from Arrays import Array\n",
105+
"\n",
106+
"def rotation(rotateBy, myArray):\n",
107+
" for i in range(0, rotateBy):\n",
108+
" rotateOne(myArray)\n",
109+
" return myArray\n",
110+
"\n",
111+
"def rotateOne(myArray):\n",
112+
" for i in range(len(myArray) - 1):\n",
113+
" myArray[i], myArray[i + 1] = myArray[i + 1], myArray[i]\n",
114+
"\n",
115+
"\n",
116+
"if __name__ == '__main__':\n",
117+
" myArray = Array(10)\n",
118+
" for i in range(len(myArray)):\n",
119+
" myArray.insert(i, i)\n",
120+
" print('Before Rotation:',myArray)\n",
121+
" print('After Rotation:',rotation(3, myArray))\n",
122+
"\n",
123+
" # OUTPUT:\n",
124+
" # Before Rotation: 0 1 2 3 4 5 6 7 8 9\n",
125+
" # After Rotation: 3 4 5 6 7 8 9 0 1 2\n"
126+
],
127+
"metadata": {
128+
"id": "m-nLEXpiYFY1"
129+
},
130+
"execution_count": null,
131+
"outputs": []
132+
}
133+
]
134+
}

0 commit comments

Comments
 (0)