diff options
Diffstat (limited to 'Practical_C_Programming/Chapter_17_1.ipynb')
-rw-r--r-- | Practical_C_Programming/Chapter_17_1.ipynb | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/Practical_C_Programming/Chapter_17_1.ipynb b/Practical_C_Programming/Chapter_17_1.ipynb new file mode 100644 index 00000000..c9e7bf83 --- /dev/null +++ b/Practical_C_Programming/Chapter_17_1.ipynb @@ -0,0 +1,97 @@ +{ + "metadata": { + "name": "Chapter 17" + }, + "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": "# Example 17.1\n# To declare a structure\n\n\n# Structure declaration\nfrom ctypes import *\n\nclass 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": "# Example 17.2\n# To look for a data item in a list\n\n\n# Function declaration\ndef 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\nname = 'Jane'\n\nif (lookup (name)) :\n print ('%s is in the list\\n' % name)\nelse :\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": "# Example 17.3\n# To insert an element at an index in a list\n\n\n# Declaration and result\naList = [45, 89, 123]\n\naList.insert(1, 53)\n\nprint '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": "# Example 17.4\n# To print the contents of a binary search tree in ASCII order\n\n\n# Class declaration\nclass Node:\n def __init__(self, val):\n self.l_child = None\n self.r_child = None\n self.data = val\n\ndef 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\ndef 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\nr = Node('Lemon')\nbinary_insert(r, Node('Plum'))\nbinary_insert(r, Node('Apple'))\nbinary_insert(r, Node('Orange'))\nbinary_insert(r, Node('Pear'))\nbinary_insert(r, Node('Grape'))\n\n\n# Result\nprint \"List of words in ASCII order:\"\nin_order_print(r)", + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": "List of words in ASCII order:\nApple\nGrape\nLemon\nOrange\nPear\nPlum\n" + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |