diff options
author | kinitrupti | 2017-05-12 18:53:46 +0530 |
---|---|---|
committer | kinitrupti | 2017-05-12 18:53:46 +0530 |
commit | f270f72badd9c61d48f290c3396004802841b9df (patch) | |
tree | bc8ba99d85644c62716ce397fe60177095b303db /Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb | |
parent | 64d949698432e05f2a372d9edc859c5b9df1f438 (diff) | |
download | Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.tar.gz Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.tar.bz2 Python-Textbook-Companions-f270f72badd9c61d48f290c3396004802841b9df.zip |
Removed duplicates
Diffstat (limited to 'Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb')
-rwxr-xr-x | Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb b/Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb new file mode 100755 index 00000000..3d179b54 --- /dev/null +++ b/Practical_C_Programming_by_Steve_Oualline/Chapter_17_1.ipynb @@ -0,0 +1,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": {} + } + ] +}
\ No newline at end of file |