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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
{
"metadata": {
"name": "",
"signature": "sha256:359ba0990b58235e80b2e0192de2b1c02844fb6d8275025bc2e3f3cf33cfcdf1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 17: Advanced Pointers "
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 17.1, Page number: 331"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"# Structure declaration\n",
"from ctypes import *\n",
"\n",
"class person (Structure) :\n",
"_fields_ = [(\"name\", c_wchar_p), (\"address\", c_wchar_p), (\"city_state_zip\", c_wchar_p), (\"age\", c_int), (\"height\", c_float)]"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 17.2, Page number: 336"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"# Function declaration\n",
"def lookup (name) :\n",
" lists = ['John', 'Jim', 'Jane', 'Clyde']\n",
" result = 0\n",
"\n",
" for index in range (0, 4) :\n",
" if (lists[index] == name) :\n",
" result = 1\n",
" break\n",
" \n",
" return result\n",
"\n",
"# Calculation and result\n",
"name = 'Jane'\n",
"\n",
"if (lookup (name)) :\n",
" print ('%s is in the list\\n' % name)\n",
"else :\n",
" print ('%s is not in the list\\n' % name)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Jane is in the list\n",
"\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 17.3, Page number: 338"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"# Declaration and result\n",
"aList = [45, 89, 123]\n",
"\n",
"aList.insert(1, 53)\n",
"\n",
"print 'Final List : ', aList"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Final List : [45, 53, 89, 123]\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Example 17.4, Page number: 348"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"\n",
"# Class declaration\n",
"class Node:\n",
" def __init__(self, val):\n",
" self.l_child = None\n",
" self.r_child = None\n",
" self.data = val\n",
"\n",
"def binary_insert(root, node):\n",
" if root is None:\n",
" root = node\n",
" else:\n",
" if root.data > node.data:\n",
" if root.l_child == None:\n",
" root.l_child = node\n",
" else:\n",
" binary_insert(root.l_child, node)\n",
" else:\n",
" if root.r_child == None:\n",
" root.r_child = node\n",
" else:\n",
" binary_insert(root.r_child, node)\n",
"\n",
"def in_order_print(root):\n",
" if not root:\n",
" return\n",
" in_order_print(root.l_child)\n",
" print root.data\n",
" in_order_print(root.r_child)\n",
"\n",
"r = Node('Lemon')\n",
"binary_insert(r, Node('Plum'))\n",
"binary_insert(r, Node('Apple'))\n",
"binary_insert(r, Node('Orange'))\n",
"binary_insert(r, Node('Pear'))\n",
"binary_insert(r, Node('Grape'))\n",
"\n",
"\n",
"# Result\n",
"print \"List of words in ASCII order:\"\n",
"in_order_print(r)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"List of words in ASCII order:\n",
"Apple\n",
"Grape\n",
"Lemon\n",
"Orange\n",
"Pear\n",
"Plum\n"
]
}
],
"prompt_number": 4
}
],
"metadata": {}
}
]
}
|