├── DS.pdf ├── LICENSE ├── README.md ├── Sources ├── Submission 1 │ ├── Screenshot from 2017-08-02 08:01:27.png │ └── stack.c ├── Submission 2 │ ├── lab1 │ │ ├── MedianOfUnsortedArray │ │ │ ├── MedianOfUnsortedArray │ │ │ ├── MedianOfUnsortedArray.cpp │ │ │ ├── Screenshot from 2017-09-10 18_55_43.png │ │ │ └── tags.LGkaD3 │ │ ├── MinMaxEleminArray │ │ │ ├── MinMaxEleminArray │ │ │ ├── MinMaxEleminArray.cpp │ │ │ └── Screenshot from 2017-09-10 18_54_39.png │ │ └── SecondLargest │ │ │ ├── Screenshot from 2017-09-10 18_53_39.png │ │ │ ├── SecondLargest │ │ │ └── SecondLargest.cpp │ ├── lab2 │ │ ├── UnionIntersection │ │ │ ├── Screenshot from 2017-09-10 17_47_16.png │ │ │ ├── UnionIntersection │ │ │ └── UnionIntersection.cpp │ │ └── multipling2Matrices │ │ │ ├── Screenshot from 2017-09-10 17_43_49.png │ │ │ ├── multipling2Matrices │ │ │ └── multipling2Matrices.cpp │ ├── lab3 │ │ ├── Sumofallinarray │ │ │ ├── Screenshot from 2017-09-10 17_50_40.png │ │ │ ├── Sumofallinarray │ │ │ └── Sumofallinarray.cpp │ │ ├── TOH │ │ │ ├── Screenshot from 2017-09-10 17_51_32.png │ │ │ ├── TOH │ │ │ └── TOH.cpp │ │ ├── gcd │ │ │ ├── Screenshot from 2017-09-10 17_49_01.png │ │ │ ├── gcd │ │ │ └── gcd.cpp │ │ └── nthFibonacci │ │ │ ├── Screenshot from 2017-09-10 17_49_30.png │ │ │ ├── nthFibonacci │ │ │ └── nthFibonacci.cpp │ ├── lab4 │ │ ├── EvenOddElemsinLL │ │ │ ├── EvenOddElemsinLL │ │ │ ├── EvenOddElemsinLL.cpp │ │ │ └── Screenshot from 2017-09-11 22-38-36.png │ │ ├── LoopinLL │ │ │ ├── LoopInLL │ │ │ ├── LoopInLL.cpp │ │ │ └── Screenshot from 2017-09-10 17_54_25.png │ │ ├── MiddleEleminLL │ │ │ ├── MiddleEleminLL │ │ │ ├── MiddleEleminLL.cpp │ │ │ └── Screenshot from 2017-09-10 17_57_33.png │ │ └── ReversingLL │ │ │ ├── ReversingLL │ │ │ ├── ReversingLL.cpp │ │ │ └── Screenshot from 2017-09-10 17_58_33.png │ ├── lab5 │ │ ├── CircularLL │ │ │ ├── CircularLL │ │ │ ├── CircularLL.cpp │ │ │ └── Screenshot from 2017-09-10 18_02_59.png │ │ ├── DoublyusingLLusingSinglyLL │ │ │ ├── DoublyLLusingSinglyLL │ │ │ ├── DoublyLLusingSinglyLL.cpp │ │ │ └── Screenshot from 2017-09-10 18_05_15.png │ │ ├── PalindromeLl │ │ │ ├── PalindromeLL │ │ │ ├── PalindromeLL.cpp │ │ │ └── Screenshot from 2017-09-10 18_07_03.png │ │ └── ReversingElemsofDoublyLL │ │ │ ├── ReversingElemsofDoublyLL │ │ │ ├── ReversingElemsofDoublyLL.cpp │ │ │ └── Screenshot from 2017-09-10 18_10_20.png │ ├── lab6 │ │ ├── GrowableStacksusingArrays │ │ │ ├── Screenshot from 2017-11-02 13-50-42.png │ │ │ ├── growableStackUsingArrays │ │ │ ├── growableStackUsingArrays.cpp │ │ │ ├── tags.7ACF2c │ │ │ ├── tags.8eYO3j │ │ │ ├── tags.LreEc3 │ │ │ ├── tags.Oe5Abw │ │ │ ├── tags.dJ1jji │ │ │ ├── tags.efXjWp │ │ │ ├── tags.is3fPk │ │ │ └── tags.xQqN9s │ │ ├── InfixToPostfix │ │ │ ├── InfixToPostfix │ │ │ ├── InfixToPostfix.cpp │ │ │ ├── Screenshot from 2017-09-11 22-35-40.png │ │ │ └── tags.ImdyM3 │ │ ├── ReverseElemOfStack │ │ │ ├── ReverseElemOfStack │ │ │ ├── ReverseElemOfStack.cpp │ │ │ └── Screenshot from 2017-09-10 18_12_46.png │ │ └── STACK_USING_LINKED_LIST │ │ │ ├── STACK_USING_LINKED_LIST │ │ │ ├── STACK_USING_LINKED_LIST.cpp │ │ │ └── Screenshot from 2017-09-10 18_14_27.png │ ├── lab7 │ │ ├── IdenticalStacks │ │ │ ├── IdenticalStacks │ │ │ ├── IdenticalStacks.cpp │ │ │ └── Screenshot from 2017-09-11 22-28-57.png │ │ ├── ImplementingStacksusingTwoQueues │ │ │ ├── ImplementStacksusingTwoQueues │ │ │ ├── ImplementStacksusingTwoQueues.cpp │ │ │ └── Screenshot from 2017-09-10 18_16_58.png │ │ └── PostfixEvaluation │ │ │ ├── PostfixEvaluation │ │ │ └── PostfixEvaluation.cpp │ └── lab8 │ │ ├── GrowableQueuesusingarrays │ │ ├── GrowableQueuesusingarrays │ │ ├── GrowableQueuesusingarrays.cpp │ │ └── Screenshot from 2017-09-11 05_12_56.png │ │ ├── ImplementDoubleEndedQueues │ │ ├── ImplementDoubleEndedQueues │ │ ├── ImplementDoubleEndedQueues.cpp │ │ └── Screenshot from 2017-09-10 18_39_16.png │ │ ├── ImplementQueuesUsingTwoStacks │ │ ├── ImplementQueuesUsingTwoStacks │ │ ├── ImplementQueuesUsingTwoStacks.cpp │ │ └── Screenshot from 2017-09-11 05_17_47.png │ │ └── QueueusingsingleLL │ │ ├── QueueusingsingleLL │ │ ├── QueueusingsingleLL.cpp │ │ └── Screenshot from 2017-09-11 05_20_48.png ├── Submission 3 │ ├── Graphs │ │ ├── Q1 │ │ │ ├── Screenshot from 2017-11-02 08-09-43.png │ │ │ ├── q1 │ │ │ └── q1.c │ │ ├── Q2 │ │ │ ├── Screenshot from 2017-11-02 08-10-55.png │ │ │ ├── q2 │ │ │ └── q2.c │ │ ├── Q3 │ │ │ ├── Screenshot from 2017-11-02 08-12-11.png │ │ │ ├── q3 │ │ │ └── q3.c │ │ └── Q4 │ │ │ ├── Screenshot from 2017-11-02 08-13-02.png │ │ │ ├── q4 │ │ │ └── q4.c │ ├── Miscellaneous │ │ ├── Q1 │ │ │ ├── Screenshot from 2017-11-02 14-12-15.png │ │ │ ├── q1 │ │ │ ├── q1.c │ │ │ └── tags.n9NQfo │ │ ├── Q2 │ │ │ ├── Screenshot from 2017-11-01 23-07-34.png │ │ │ ├── cubed │ │ │ └── cubed.c │ │ ├── Q3 │ │ │ ├── Q3.png │ │ │ ├── q3 │ │ │ └── q3.c │ │ └── Q4 │ │ │ ├── Screenshot from 2017-11-02 09-00-19.png │ │ │ ├── q4 │ │ │ └── q4.c │ ├── Sorting │ │ ├── Insertion sort │ │ │ ├── Screenshot from 2017-11-01 13-59-55.png │ │ │ ├── insertionsort │ │ │ ├── insertionsort.c │ │ │ ├── tags.6f7LY8 │ │ │ └── tags.dwMi4j │ │ ├── Merge sort │ │ │ ├── Merge sort.png │ │ │ ├── mergesort │ │ │ └── mergesort.c │ │ ├── Quick sort │ │ │ ├── Quick sort.png │ │ │ ├── quicksort │ │ │ └── quicksort.c │ │ ├── Radix sort │ │ │ ├── Radix sort.png │ │ │ ├── radixsort │ │ │ └── radixsort.c │ │ └── Selection sort │ │ │ ├── Selection sort.png │ │ │ ├── selectionsort │ │ │ └── selectionsort.c │ └── Trees │ │ ├── Q1 │ │ ├── Screenshot from 2017-11-01 18-32-47.png │ │ ├── q1 │ │ └── q1.c │ │ ├── Q2 │ │ ├── Screenshot from 2017-11-01 18-34-42.png │ │ ├── q2 │ │ └── q2.c │ │ ├── Q3 │ │ ├── Screenshot from 2017-11-01 18-35-55.png │ │ ├── q3 │ │ └── q3.c │ │ ├── Q4 │ │ ├── Screenshot from 2017-11-01 18-54-29.png │ │ ├── q4 │ │ └── q4.c │ │ ├── Q5 │ │ ├── Screenshot from 2017-11-01 19-02-40.png │ │ ├── q5 │ │ └── q5.c │ │ ├── Q6 │ │ ├── Q6_NR.png │ │ ├── q6 │ │ ├── q6.c │ │ ├── q6NR │ │ ├── q6NR.c │ │ └── q6_RECURSIVE.png │ │ └── Q7 │ │ ├── Screenshot from 2017-11-01 21-49-56.png │ │ ├── q7 │ │ └── q7.c └── robots.txt └── resources ├── Screenshot from 2017-09-10 17_51_32.png ├── Screenshot from 2017-11-02 08-10-55.png └── robots.txt /DS.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/DS.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :ledger: CSE-217-Data-Structures-Laboratory 2 | > Data Structures Laboratory programs in C prgramming language of CSE-217 (Winter 2017). This repository contains programs of various introductory data structures implemented in C/C++ programming language tested on gcc (linux). It also contains screenshots of operational windows in Ubuntu 17.04 (For usage). 3 | 4 | ## How to run a C/C++ program using make in terminal (Linux)? 5 | 6 | Extract the master branch in home directory. Open terminal and type in the code there. Let's say merge sort which is named as mergesort in directory Sources/Submission%203/Sorting/Merge%20sort/. 7 | 8 | ```cd ./Sources/Submission%203/Sorting/Merge%20sort/``` 9 | 10 | ```make mergesort``` 11 | 12 | ```./mergesort``` 13 | 14 | ## Sample Screenshots 15 | ![](https://github.com/Jishanshaikh4/CSE-217-Data-Structures-Laboratory/blob/master/resources/Screenshot%20from%202017-09-10%2017_51_32.png) 16 | ![](https://github.com/Jishanshaikh4/CSE-217-Data-Structures-Laboratory/blob/master/resources/Screenshot%20from%202017-11-02%2008-10-55.png) 17 | 18 | ## Licence 19 | The programs are licenced under GPL-3.0, but DS.pdf may not be used for otherwise purposes. 20 | 21 | ![](https://www.gnu.org/graphics/gplv3-127x51.png) 22 | -------------------------------------------------------------------------------- /Sources/Submission 1/Screenshot from 2017-08-02 08:01:27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 1/Screenshot from 2017-08-02 08:01:27.png -------------------------------------------------------------------------------- /Sources/Submission 1/stack.c: -------------------------------------------------------------------------------- 1 | // stack.c tested on gcc linux. 2 | 3 | #include 4 | #include 5 | 6 | #define max_size 500 7 | 8 | int stack[max_size],top=-1; 9 | 10 | void push(); 11 | void pop(); 12 | void peek(); 13 | void display(); 14 | 15 | int main(){ 16 | int choice; 17 | do{ 18 | printf("\n\n**********MAIN MENU**********\n"); 19 | printf("1.Push\n"); 20 | printf("2.Pop\n"); 21 | printf("3.Peep\n"); 22 | printf("4.Display\n"); 23 | printf("5.Exit\n"); 24 | printf("*********************************"); 25 | 26 | printf("\nEnter your choice:\t"); 27 | scanf("%d",&choice); 28 | 29 | switch(choice){ 30 | case 1: 31 | push(); 32 | break; 33 | case 2: 34 | pop(); 35 | break; 36 | case 3: 37 | peek(); 38 | break; 39 | case 4: 40 | display(); 41 | break; 42 | case 5: 43 | exit(0); 44 | break; 45 | default: 46 | printf("\nInvalid choice:\n"); 47 | break; 48 | } 49 | }while(choice!=5); 50 | return 0; 51 | } 52 | void push(){ 53 | int item; 54 | if(top==(max_size-1)){ 55 | printf("\nStack Overflow:"); 56 | } 57 | else{ 58 | printf("Enter the element to be inserted:\t"); 59 | scanf("%d",&item); 60 | top=top+1; 61 | stack[top]=item; 62 | } 63 | } 64 | void pop(){ 65 | int item; 66 | if(top==-1){ 67 | printf("Stack Underflow:"); 68 | } 69 | else{ 70 | item=stack[top]; 71 | top=top-1; 72 | printf("\nThe poped element: %d\t",item); 73 | } 74 | } 75 | void peek(){ 76 | if(top==-1){ 77 | printf("\nStack is empty:"); 78 | } 79 | else{ 80 | printf("The topmost element of the stack is %d",stack[top]); 81 | } 82 | } 83 | void display(){ 84 | int i; 85 | if(top==-1){ 86 | printf("\nStack is Empty:"); 87 | } 88 | else{ 89 | printf("\nThe stack elements are:\n" ); 90 | for(i=top;i>=0;i--){ 91 | printf("%d\n",stack[i]); 92 | } 93 | } 94 | } 95 | // End of stack.c 96 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab1/MedianOfUnsortedArray/MedianOfUnsortedArray: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab1/MedianOfUnsortedArray/MedianOfUnsortedArray -------------------------------------------------------------------------------- /Sources/Submission 2/lab1/MedianOfUnsortedArray/MedianOfUnsortedArray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cout<<"Enter number of elements in array: "; 8 | cin>>n; 9 | int arr[n],temp; 10 | cout<<"Enter elements of array:"<>arr[i]; 13 | for(int j=0; j 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int max=0, min, n; 7 | cout<<"Enter the number of elements: "; 8 | cin>>n; 9 | int arr[n]; 10 | cout<<"Enter elements of array:"; 11 | for(int i=0; i>arr[i]; 13 | max=arr[0]; 14 | for(int j=1; jmax) 16 | { 17 | max= arr[j]; 18 | } 19 | } 20 | min= arr[0]; 21 | for(int k=1; k 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cout<<"Enter number of elements in array: "; 8 | cin>>n; 9 | int arr[n],temp; 10 | cout<<"Enter elements of array:"<>arr[i]; 13 | for(int j=0; j 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int binarySearch(int arr[], int l, int r, int x); 8 | 9 | void printUnion(int arr1[], int arr2[], int m, int n){ 10 | if(m>n){ 11 | int *tempp=arr1; 12 | arr1=arr2; 13 | arr2=tempp; 14 | 15 | int temp=m; 16 | m=n; 17 | n=temp; 18 | } 19 | sort(arr1, arr1+m); 20 | for (int i=0; in){ 30 | int *tempp=arr1; 31 | arr1=arr2; 32 | arr2=tempp; 33 | 34 | int temp=m; 35 | m=n; 36 | n=temp; 37 | } 38 | sort(arr1, arr1 + m); 39 | 40 | for (int i=0; i=l) 46 | { 47 | int mid=l+(r-l)/2; 48 | if (arr[mid]==x) return mid; 49 | if (arr[mid]>x) return binarySearch(arr, l, mid-1, x); 50 | return binarySearch(arr, mid+1, r, x); 51 | } 52 | return -1; 53 | } 54 | int main(){ 55 | int arr1[]={7, 1, 5, 2, 3, 6}; 56 | int arr2[]={3, 8, 6, 20, 7}; 57 | int m=sizeof(arr1)/sizeof(arr1[0]); 58 | int n=sizeof(arr2)/sizeof(arr2[0]); 59 | cout<<"Union of two arrays is :"; 60 | printUnion(arr1, arr2, m, n); 61 | cout<<"\nIntersection of two arrays is : "; 62 | printIntersection(arr1, arr2, m, n); 63 | printf("\n"); 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab2/multipling2Matrices/Screenshot from 2017-09-10 17_43_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab2/multipling2Matrices/Screenshot from 2017-09-10 17_43_49.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab2/multipling2Matrices/multipling2Matrices: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab2/multipling2Matrices/multipling2Matrices -------------------------------------------------------------------------------- /Sources/Submission 2/lab2/multipling2Matrices/multipling2Matrices.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int m, n, p, q, c, d, k, sum=0; 5 | int first[10][10], second[10][10], multiply[10][10]; 6 | 7 | printf("Enter the number of rows and columns of first matrix\n"); 8 | scanf("%d%d", &m, &n); 9 | printf("Enter the elements of first matrix\n"); 10 | 11 | for (c=0; c 2 | 3 | int findSum(int A[], int n){ 4 | if (n<=0) 5 | return 0; 6 | return (findSum(A, n-1)+A[n-1]); 7 | } 8 | 9 | int main(){ 10 | int n; 11 | printf("Enter Number of Elements: "); 12 | scanf("%d",&n); 13 | int A[n]; 14 | for(int i=0;i 2 | 3 | void towers(int num, char frompeg, char topeg, char auxpeg){ 4 | if(num==1){ 5 | printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg); 6 | return; 7 | } 8 | towers(num - 1, frompeg, auxpeg, topeg); 9 | printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg); 10 | towers(num - 1, auxpeg, topeg, frompeg); 11 | } 12 | 13 | int main(){ 14 | int num; 15 | printf("Enter the number of disks : "); 16 | scanf("%d", &num); 17 | printf("The sequence of moves involved in the Tower of Hanoi are :\n"); 18 | towers(num, 'A', 'C', 'B'); 19 | printf("\n"); 20 | return 0; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/gcd/Screenshot from 2017-09-10 17_49_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab3/gcd/Screenshot from 2017-09-10 17_49_01.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/gcd/gcd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab3/gcd/gcd -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/gcd/gcd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int gcd(int a, int b); 4 | 5 | int main(){ 6 | int n1, n2, s; 7 | printf("Enter two integers: "); 8 | scanf("%d %d",&n1,&n2); 9 | s=gcd(n1, n2); 10 | printf("The gcd of entered two numbers is %d\n",s); 11 | return 0; 12 | } 13 | 14 | int gcd(int a, int b){ 15 | if(a<0) 16 | a=-a; 17 | if(b<0) 18 | b=-b; 19 | if(a==b) 20 | return a; 21 | else 22 | return (gcd(b,a-b)); 23 | } 24 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/nthFibonacci/Screenshot from 2017-09-10 17_49_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab3/nthFibonacci/Screenshot from 2017-09-10 17_49_30.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/nthFibonacci/nthFibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab3/nthFibonacci/nthFibonacci -------------------------------------------------------------------------------- /Sources/Submission 2/lab3/nthFibonacci/nthFibonacci.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int fibo(int); 4 | 5 | int main(){ 6 | int num; 7 | int result; 8 | printf("Enter the nth number in fibonacci series: "); 9 | scanf("%d", &num); 10 | if (num<0){ 11 | printf("Please Enter Positive number!!!\n"); 12 | } 13 | else{ 14 | result=fibo(num); 15 | printf("The %d number in fibonacci series is %d\n", num, result); 16 | } 17 | return 0; 18 | } 19 | 20 | int fibo(int num){ 21 | if (num==0){ 22 | return 0; 23 | } 24 | else if(num==1){ 25 | return 1; 26 | } 27 | else{ 28 | return(fibo(num - 1)+fibo(num - 2)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/EvenOddElemsinLL/EvenOddElemsinLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/EvenOddElemsinLL/EvenOddElemsinLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/EvenOddElemsinLL/EvenOddElemsinLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int num; 6 | struct node *next; 7 | }; 8 | 9 | void create(struct node **head){ 10 | int c, ch; 11 | struct node *temp, *rear; 12 | do{ 13 | printf("Enter number: "); 14 | scanf("%d", &c); 15 | temp = (struct node *)malloc(sizeof(struct node)); 16 | temp->num = c; 17 | temp->next = NULL; 18 | if (*head == NULL){ 19 | *head = temp; 20 | } 21 | else{ 22 | rear->next = temp; 23 | } 24 | rear = temp; 25 | printf("Do you wish to continue [1/0]: "); 26 | scanf("%d", &ch); 27 | }while(ch!=0); 28 | printf("\n"); 29 | } 30 | 31 | void generate_evenodd(struct node *list, struct node **head){ 32 | struct node *even = NULL, *odd = NULL, *temp; 33 | struct node *reven, *rodd; 34 | while (list != NULL){ 35 | temp = (struct node *)malloc(sizeof(struct node)); 36 | temp->num = list->num; 37 | temp->next = NULL; 38 | if (list->num % 2 == 0){ 39 | if (even == NULL){ 40 | even = temp; 41 | } 42 | else{ 43 | reven->next = temp; 44 | } 45 | reven = temp; 46 | } 47 | else{ 48 | if (odd == NULL){ 49 | odd = temp; 50 | } 51 | else{ 52 | rodd->next = temp; 53 | } 54 | rodd = temp; 55 | } 56 | list = list->next; 57 | } 58 | reven->next = odd; 59 | *head = even; 60 | } 61 | 62 | void release(struct node **head) 63 | { 64 | struct node *temp = *head; 65 | *head = (*head)->next; 66 | while ((*head) != NULL) 67 | { 68 | free(temp); 69 | temp = *head; 70 | (*head) = (*head)->next; 71 | } 72 | } 73 | 74 | void display(struct node *p) 75 | { 76 | while (p != NULL) 77 | { 78 | printf("%d\t", p->num); 79 | p = p->next; 80 | } 81 | printf("\n"); 82 | } 83 | 84 | 85 | int main() 86 | { 87 | struct node *p = NULL, *q = NULL; 88 | int key, result; 89 | printf("Enter data into the list\n"); 90 | create(&p); 91 | printf("Displaying the nodes in the list:\n"); 92 | display(p); 93 | generate_evenodd(p, &q); 94 | printf("Displaying the list with even and then odd:\n"); 95 | display(q); 96 | release(&p); 97 | return 0; 98 | } 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/EvenOddElemsinLL/Screenshot from 2017-09-11 22-38-36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/EvenOddElemsinLL/Screenshot from 2017-09-11 22-38-36.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/LoopinLL/LoopInLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/LoopinLL/LoopInLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/LoopinLL/LoopInLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int num; 6 | struct node *next; 7 | }; 8 | 9 | void create(struct node **head){ 10 | int c, ch; 11 | struct node *temp, *rear; 12 | do{ 13 | printf("Enter number: "); 14 | scanf("%d", &c); 15 | temp=(struct node *)malloc(sizeof(struct node)); 16 | temp->num=c; 17 | temp->next=NULL; 18 | if (*head==NULL){ 19 | *head=temp; 20 | } 21 | else{ 22 | rear->next=temp; 23 | } 24 | rear=temp; 25 | printf("Do you wish to continue [1/0]: "); 26 | scanf("%d", &ch); 27 | } while (ch!=0); 28 | printf("\n"); 29 | } 30 | void makecycle(struct node **p){ 31 | struct node *rear, *front; 32 | int n, count=0, i; 33 | front=rear=*p; 34 | while (rear->next!=NULL){ 35 | rear=rear->next; 36 | count++; 37 | } 38 | if (count) 39 | n=rand() % count; 40 | else 41 | n=1; 42 | 43 | for (i=0; inext; 45 | rear->next=front; 46 | } 47 | void release(struct node **head){ 48 | struct node *temp=*head; 49 | temp=temp->next; 50 | while ((*head)!=NULL){ 51 | free(temp); 52 | temp=*head; 53 | (*head)=(*head)->next; 54 | } 55 | } 56 | int detectcycle(struct node *head){ 57 | int flag=1, count=1, i; 58 | struct node *p, *q; 59 | p=q=head; 60 | q=q->next; 61 | while (1){ 62 | q=q->next; 63 | if (flag){ 64 | p=p->next; 65 | } 66 | if (q==p){ 67 | q=q->next; 68 | while (q!=p){ 69 | count++; 70 | q=q->next; 71 | } 72 | q=p=head; 73 | for (i=0; inext; 75 | } 76 | while (p!=q){ 77 | p=p->next; 78 | q=q->next; 79 | } 80 | q->next=NULL; 81 | return 1; 82 | } 83 | else if (q->next==NULL){ 84 | return 0; 85 | } 86 | flag=!flag; 87 | } 88 | } 89 | 90 | 91 | int main(){ 92 | struct node *p=NULL; 93 | int result; 94 | printf("Enter data into the list\n"); 95 | create(&p); 96 | makecycle(&p); //comment it to avoid cycle creation 97 | printf("Working...\n"); 98 | result=detectcycle(p); 99 | if (result){ 100 | printf("Cycle detected in the linked list.\n"); 101 | } 102 | else{ 103 | printf("No cycle detected in the linked list.\n"); 104 | } 105 | release (&p); 106 | return 0; 107 | } 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/LoopinLL/Screenshot from 2017-09-10 17_54_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/LoopinLL/Screenshot from 2017-09-10 17_54_25.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/MiddleEleminLL/MiddleEleminLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/MiddleEleminLL/MiddleEleminLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/MiddleEleminLL/MiddleEleminLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node{ 5 | int data; 6 | struct Node* next; 7 | }; 8 | 9 | void printMiddle(struct Node *head){ 10 | struct Node *slow_ptr=head; 11 | struct Node *fast_ptr=head; 12 | 13 | if (head!=NULL){ 14 | while (fast_ptr!=NULL && fast_ptr->next!=NULL){ 15 | fast_ptr=fast_ptr->next->next; 16 | slow_ptr=slow_ptr->next; 17 | } 18 | printf("The middle element is [%d]\n\n", slow_ptr->data); 19 | } 20 | } 21 | 22 | void push(struct Node** head_ref, int new_data){ 23 | struct Node* new_node=(struct Node*) malloc(sizeof(struct Node)); 24 | new_node->data =new_data; 25 | new_node->next=(*head_ref); 26 | (*head_ref)=new_node; 27 | } 28 | 29 | void printList(struct Node *ptr){ 30 | while (ptr!=NULL){ 31 | printf("%d->", ptr->data); 32 | ptr=ptr->next; 33 | } 34 | printf("NULL\n"); 35 | } 36 | 37 | int main(){ 38 | struct Node* head=NULL; 39 | int i; 40 | for (i=1; i<10; i++){ 41 | push(&head, i); 42 | printList(head); 43 | printMiddle(head); 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/MiddleEleminLL/Screenshot from 2017-09-10 17_57_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/MiddleEleminLL/Screenshot from 2017-09-10 17_57_33.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/ReversingLL/ReversingLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/ReversingLL/ReversingLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/ReversingLL/ReversingLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct node{ 4 | int num; 5 | struct node *next; 6 | }; 7 | void create(struct node **head){ 8 | int c, ch; 9 | struct node *temp, *rear; 10 | do{ 11 | printf("Enter number: "); 12 | scanf("%d", &c); 13 | temp=(struct node *)malloc(sizeof(struct node)); 14 | temp->num=c; 15 | temp->next=NULL; 16 | if (*head==NULL){ 17 | *head=temp; 18 | } 19 | else{ 20 | rear->next=temp; 21 | } 22 | rear=temp; 23 | printf("Do you wish to continue [1/0]: "); 24 | scanf("%d", &ch); 25 | }while (ch!=0); 26 | printf("\n"); 27 | } 28 | void reverse(struct node **head){ 29 | struct node *p, *q, *r; 30 | p=q=r=*head; 31 | p=p->next->next; 32 | q=q->next; 33 | r->next=NULL; 34 | q->next=r; 35 | while (p!=NULL){ 36 | r=q; 37 | q=p; 38 | p=p->next; 39 | q->next=r; 40 | } 41 | *head=q; 42 | } 43 | void release(struct node **head){ 44 | struct node *temp=*head; 45 | *head=(*head)->next; 46 | while ((*head)!=NULL){ 47 | free(temp); 48 | temp=*head; 49 | (*head)=(*head)->next; 50 | } 51 | } 52 | void display(struct node *p){ 53 | while (p!=NULL){ 54 | printf("%d\t", p->num); 55 | p=p->next; 56 | } 57 | printf("\n"); 58 | } 59 | 60 | int main(){ 61 | struct node *p=NULL; 62 | int n; 63 | printf("Enter data into the list\n"); 64 | create(&p); 65 | printf("Before reversing the list:\n"); 66 | display(p); 67 | printf("Reversing the list...\n"); 68 | reverse(&p); 69 | printf("After reversing list:\n"); 70 | display(p); 71 | release(&p); 72 | return 0; 73 | } 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab4/ReversingLL/Screenshot from 2017-09-10 17_58_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab4/ReversingLL/Screenshot from 2017-09-10 17_58_33.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/CircularLL/CircularLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/CircularLL/CircularLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/CircularLL/CircularLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *link; 7 | }; 8 | 9 | struct node *head=NULL, *x, *y, *z; 10 | void create(); 11 | void ins_at_beg(); 12 | void ins_at_pos(); 13 | void del_at_beg(); 14 | void del_at_pos(); 15 | void traverse(); 16 | 17 | int main(){ 18 | int ch; 19 | printf("\nEnter your choice (1,2,3,4,5,6,10) : \n\n"); 20 | printf("\n 1.Creation \n 2.Insertion at beginning \n 3.Insertion at remaining"); 21 | printf("\n 4.Deletion at beginning \n 5.Deletion at remaining \n 6.only traverse"); 22 | printf("\n 10.Exit\n"); 23 | while(1){ 24 | printf("\n Enter your choice:"); 25 | scanf("%d", &ch); 26 | switch(ch){ 27 | case 1: 28 | create(); 29 | break; 30 | case 2: 31 | ins_at_beg(); 32 | break; 33 | case 3: 34 | ins_at_pos(); 35 | break; 36 | case 4: 37 | del_at_beg(); 38 | break; 39 | case 5: 40 | del_at_pos(); 41 | break; 42 | case 6: 43 | traverse(); 44 | break; 45 | default: 46 | exit(0); 47 | } 48 | } 49 | return 0; 50 | } 51 | 52 | void create(){ 53 | int c; 54 | x=(struct node*)malloc(sizeof(struct node)); 55 | printf("\n Enter the data:"); 56 | scanf("%d", &x->data); 57 | x->link=x; 58 | head=x; 59 | printf("\n If you wish to continue press 1 otherwise 0:"); 60 | scanf("%d", &c); 61 | while (c!=0){ 62 | y=(struct node*)malloc(sizeof(struct node)); 63 | printf("\n Enter the data:"); 64 | scanf("%d", &y->data); 65 | x->link=y; 66 | y->link=head; 67 | x=y; 68 | printf("\n If you wish to continue press 1 otherwise 0:"); 69 | scanf("%d", &c); 70 | } 71 | } 72 | 73 | void ins_at_beg(){ 74 | x=head; 75 | y=(struct node*)malloc(sizeof(struct node)); 76 | printf("\n Enter the data:"); 77 | scanf("%d", &y->data); 78 | while (x->link!=head){ 79 | x=x->link; 80 | } 81 | x->link=y; 82 | y->link=head; 83 | head=y; 84 | } 85 | 86 | void ins_at_pos(){ 87 | struct node *ptr; 88 | int c=1, pos, count=1; 89 | y=(struct node*)malloc(sizeof(struct node)); 90 | if (head==NULL){ 91 | printf("cannot enter an element at this place"); 92 | } 93 | printf("\n Enter the data:"); 94 | scanf("%d", &y->data); 95 | printf("\n Enter the position to be inserted:"); 96 | scanf("%d", &pos); 97 | x=head; 98 | ptr=head; 99 | while (ptr->link!=head){ 100 | count++; 101 | ptr=ptr->link; 102 | } 103 | count++; 104 | if (pos>count){ 105 | printf("OUT OF BOUND"); 106 | return; 107 | } 108 | while (clink; 111 | c++; 112 | } 113 | y->link=x; 114 | z->link=y; 115 | } 116 | 117 | void del_at_beg(){ 118 | if (head==NULL) 119 | printf("\n List is empty"); 120 | else{ 121 | x=head; 122 | y=head; 123 | while (x->link!=head){ 124 | x=x->link; 125 | } 126 | head=y->link; 127 | x->link=head; 128 | free(y); 129 | } 130 | } 131 | 132 | void del_at_pos(){ 133 | if (head==NULL) 134 | printf("\n List is empty"); 135 | else{ 136 | int c=1, pos; 137 | printf("\n Enter the position to be deleted:"); 138 | scanf("%d", &pos); 139 | x=head; 140 | while (clink; 143 | c++; 144 | } 145 | y->link=x->link; 146 | free(x); 147 | } 148 | } 149 | 150 | void traverse(){ 151 | if (head==NULL) 152 | printf("\n List is empty"); 153 | else{ 154 | x=head; 155 | while (x->link!=head){ 156 | printf("%d->", x->data); 157 | x=x->link; 158 | } 159 | printf("%d", x->data); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/CircularLL/Screenshot from 2017-09-10 18_02_59.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/CircularLL/Screenshot from 2017-09-10 18_02_59.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/DoublyusingLLusingSinglyLL/DoublyLLusingSinglyLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/DoublyusingLLusingSinglyLL/DoublyLLusingSinglyLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/DoublyusingLLusingSinglyLL/DoublyLLusingSinglyLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int num; 6 | struct node *next; 7 | }; 8 | 9 | void create(struct node **); 10 | void move (struct node *); 11 | void release(struct node **); 12 | void display(struct node *); 13 | 14 | int main(){ 15 | struct node *p=NULL, *q=NULL; 16 | int result, count; 17 | printf("\nEnter data into the list\n"); 18 | create(&p); 19 | printf("Displaying list:\n"); 20 | display(p); 21 | move(p); 22 | release (&p); 23 | return 0; 24 | } 25 | void move(struct node *head){ 26 | struct node *p, *q; 27 | int ch; 28 | p=q=head; 29 | printf("\nPointer at %d\n", head->num); 30 | do{ 31 | printf("Select option:\n1. Move front\n2. Move back\n3. Exit\nYour choice: "); 32 | scanf("%d", &ch); 33 | switch(ch){ 34 | case 1: if(q->next!=NULL){ 35 | q=q->next; 36 | printf("\nPointer at %d\n", q->num); 37 | } 38 | else{ 39 | printf("\nPointer at last node %d. Cannot move ahead.\n", q->num); 40 | } 41 | break; 42 | 43 | case 2: while (p->next!=q) 44 | p=p->next; 45 | if (p==q) 46 | printf("\nPointer at first node %d. Cannot move behind.\n", q->num); 47 | else{ 48 | q=p; 49 | p=head; 50 | printf("\nPointer at %d\n", q->num); 51 | } 52 | break; 53 | case 3: 54 | return; 55 | default: printf("\nInvalid choice entered. Try again\n"); 56 | } 57 | }while (1); 58 | } 59 | 60 | void create(struct node **head){ 61 | int c, ch; 62 | struct node *temp, *rear; 63 | do{ 64 | printf("Enter number: "); 65 | scanf("%d", &c); 66 | temp=(struct node *)malloc(sizeof(struct node)); 67 | temp->num=c; 68 | temp->next=NULL; 69 | if (*head==NULL){ 70 | *head=temp; 71 | } 72 | else{ 73 | rear->next=temp; 74 | } 75 | rear=temp; 76 | printf("Do you wish to continue [1/0]: "); 77 | scanf("%d", &ch); 78 | }while (ch!=0); 79 | printf("\n"); 80 | } 81 | 82 | void display(struct node *head){ 83 | while (head!=NULL){ 84 | printf("%d\t", head->num); 85 | head=head->next; 86 | } 87 | printf("\n"); 88 | } 89 | 90 | void release(struct node **head){ 91 | struct node *temp; 92 | while ((*head)!=NULL){ 93 | temp=*head; 94 | (*head)=(*head)->next; 95 | free(temp); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/DoublyusingLLusingSinglyLL/Screenshot from 2017-09-10 18_05_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/DoublyusingLLusingSinglyLL/Screenshot from 2017-09-10 18_05_15.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/PalindromeLl/PalindromeLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/PalindromeLl/PalindromeLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/PalindromeLl/PalindromeLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Node{ 6 | char data; 7 | struct Node* next; 8 | }; 9 | 10 | void reverse(struct Node**); 11 | bool compareLists(struct Node*, struct Node *); 12 | 13 | bool isPalindrome(struct Node *head){ 14 | struct Node *slow_ptr=head, *fast_ptr=head; 15 | struct Node *second_half, *prev_of_slow_ptr=head; 16 | struct Node *midnode=NULL; 17 | bool res=true; 18 | if (head!=NULL && head->next!=NULL){ 19 | while (fast_ptr!=NULL && fast_ptr->next!=NULL){ 20 | fast_ptr=fast_ptr->next->next; 21 | prev_of_slow_ptr=slow_ptr; 22 | slow_ptr=slow_ptr->next; 23 | } 24 | if (fast_ptr!=NULL){ 25 | midnode=slow_ptr; 26 | slow_ptr=slow_ptr->next; 27 | } 28 | second_half=slow_ptr; 29 | prev_of_slow_ptr->next=NULL; 30 | reverse(&second_half); 31 | res=compareLists(head, second_half); 32 | 33 | reverse(&second_half); 34 | if (midnode!=NULL){ 35 | prev_of_slow_ptr->next=midnode; 36 | midnode->next=second_half; 37 | } 38 | else prev_of_slow_ptr->next=second_half; 39 | } 40 | return res; 41 | } 42 | 43 | void reverse(struct Node** head_ref){ 44 | struct Node* prev =NULL; 45 | struct Node* current=*head_ref; 46 | struct Node* next; 47 | while (current!=NULL){ 48 | next=current->next; 49 | current->next=prev; 50 | prev=current; 51 | current=next; 52 | } 53 | *head_ref=prev; 54 | } 55 | 56 | bool compareLists(struct Node* head1, struct Node *head2){ 57 | struct Node* temp1=head1; 58 | struct Node* temp2=head2; 59 | 60 | while (temp1 && temp2){ 61 | if (temp1->data==temp2->data){ 62 | temp1=temp1->next; 63 | temp2=temp2->next; 64 | } 65 | else return 0; 66 | } 67 | if (temp1==NULL && temp2==NULL) 68 | return 1; 69 | return 0; 70 | } 71 | 72 | void push(struct Node** head_ref, char new_data){ 73 | struct Node* new_node=(struct Node*) malloc(sizeof(struct Node)); 74 | new_node->data=new_data; 75 | new_node->next=(*head_ref); 76 | (*head_ref) =new_node; 77 | } 78 | 79 | void printList(struct Node *ptr){ 80 | while (ptr!=NULL){ 81 | printf("%c->", ptr->data); 82 | ptr=ptr->next; 83 | } 84 | printf("NULL\n"); 85 | } 86 | 87 | int main(){ 88 | struct Node* head=NULL; 89 | char str[]="JISHAN SHAIKH"; 90 | int i; 91 | 92 | for (i=0; str[i]!='\0'; i++){ 93 | push(&head, str[i]); 94 | printList(head); 95 | isPalindrome(head)? printf("Is Palindrome\n\n"): 96 | printf("Not Palindrome\n\n"); 97 | } 98 | 99 | return 0; 100 | } 101 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/PalindromeLl/Screenshot from 2017-09-10 18_07_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/PalindromeLl/Screenshot from 2017-09-10 18_07_03.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/ReversingElemsofDoublyLL/ReversingElemsofDoublyLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/ReversingElemsofDoublyLL/ReversingElemsofDoublyLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/ReversingElemsofDoublyLL/ReversingElemsofDoublyLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node{ 5 | int data; 6 | struct Node *next; 7 | struct Node *prev; 8 | }; 9 | 10 | void reverse(struct Node **head_ref){ 11 | struct Node *temp=NULL; 12 | struct Node *current=*head_ref; 13 | 14 | while (current!=NULL){ 15 | temp=current->prev; 16 | current->prev=current->next; 17 | current->next=temp; 18 | current=current->prev; 19 | } 20 | if(temp!=NULL) 21 | *head_ref=temp->prev; 22 | } 23 | 24 | void push(struct Node** head_ref, int new_data){ 25 | struct Node* new_node=(struct Node*) malloc(sizeof(struct Node)); 26 | 27 | new_node->data=new_data; 28 | new_node->prev=NULL; 29 | 30 | new_node->next=(*head_ref); 31 | 32 | if((*head_ref)!=NULL) 33 | (*head_ref)->prev=new_node ; 34 | 35 | (*head_ref)=new_node; 36 | } 37 | 38 | void printList(struct Node *node){ 39 | while(node!=NULL) 40 | { 41 | printf("%d ", node->data); 42 | node=node->next; 43 | } 44 | } 45 | 46 | int main(){ 47 | struct Node* head=NULL; 48 | 49 | push(&head, 2); 50 | push(&head, 4); 51 | push(&head, 8); 52 | push(&head, 10); 53 | 54 | printf("\n Original Linked list "); 55 | printList(head); 56 | 57 | reverse(&head); 58 | 59 | printf("\n Reversed Linked list "); 60 | printList(head); 61 | printf("\n"); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab5/ReversingElemsofDoublyLL/Screenshot from 2017-09-10 18_10_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab5/ReversingElemsofDoublyLL/Screenshot from 2017-09-10 18_10_20.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/Screenshot from 2017-11-02 13-50-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/GrowableStacksusingArrays/Screenshot from 2017-11-02 13-50-42.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/growableStackUsingArrays: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/GrowableStacksusingArrays/growableStackUsingArrays -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/growableStackUsingArrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int data; 7 | struct node *link; 8 | }*top = NULL; 9 | 10 | #define MAX 5 11 | void push(); 12 | void pop(); 13 | void empty(); 14 | void stack_full(); 15 | int stack_count(); 16 | void destroy(); 17 | void print_top(); 18 | 19 | int main(){ 20 | int choice; 21 | 22 | while (1){ 23 | printf("1. push an element \n"); 24 | printf("2. pop an element \n"); 25 | printf("3. check if stack is empty \n"); 26 | printf("4. check if stack is full \n"); 27 | printf("5. count/display elements present in stack \n"); 28 | printf("6. empty and destroy stack \n"); 29 | printf("7. Print top of the stack \n"); 30 | printf("8. exit \n"); 31 | printf("Enter your choice \n"); 32 | scanf("%d",&choice); 33 | switch (choice){ 34 | case 1: 35 | push(); 36 | break; 37 | case 2: 38 | pop(); 39 | break; 40 | case 3: 41 | empty(); 42 | break; 43 | case 4: 44 | stack_full(); 45 | break; 46 | case 5: 47 | stack_count(); 48 | break; 49 | case 6: 50 | destroy(); 51 | break; 52 | case 7: 53 | print_top(); 54 | break; 55 | case 8: 56 | return 0; 57 | default: 58 | printf("wrong choice\n"); 59 | } 60 | } 61 | } 62 | 63 | void push(){ 64 | int val,count; 65 | struct node *temp; 66 | temp = (struct node*)malloc(sizeof(struct node)); 67 | 68 | count = stack_count(); 69 | if (count <= MAX - 1){ 70 | printf("\nEnter value which you want to push into the stack :\n"); 71 | scanf("%d",&val); 72 | temp->data = val; 73 | temp->link = top; 74 | top = temp; 75 | } 76 | else 77 | printf("WARNING: STACK FULL\n"); 78 | } 79 | 80 | void pop(){ 81 | struct node *temp; 82 | if (top==NULL) 83 | printf("**Stack is empty**\n"); 84 | else 85 | { 86 | temp = top; 87 | printf("Value popped out is %d \n",temp->data); 88 | top = top->link; 89 | free(temp); 90 | } 91 | } 92 | void empty() 93 | { 94 | if (top == NULL) 95 | printf("STACK IS EMPTY\n"); 96 | else 97 | printf("elements are present, stack is not empty \n"); 98 | } 99 | 100 | void stack_full() 101 | { 102 | int count; 103 | 104 | count = stack_count(); 105 | if (count==MAX) 106 | { 107 | printf("stack is full\n"); 108 | } 109 | else 110 | printf("stack is not full \n"); 111 | } 112 | 113 | int stack_count() 114 | { 115 | int count = 0; 116 | struct node *temp; 117 | 118 | temp = top; 119 | while (temp!=NULL) 120 | { 121 | printf(" %d\n",temp->data); 122 | temp = temp->link; 123 | count++; 124 | } 125 | return count; 126 | } 127 | 128 | int st_count() 129 | { 130 | int count = 0; 131 | struct node *temp; 132 | temp = top; 133 | while (temp!=NULL) 134 | { 135 | temp = temp->link; 136 | count++; 137 | } 138 | return count; 139 | } 140 | void destroy() 141 | { 142 | struct node *temp; 143 | temp = top; 144 | while (temp!=NULL) 145 | { 146 | pop(); 147 | temp = temp->link; 148 | } 149 | printf("stack destroyed\n"); 150 | } 151 | 152 | void print_top() 153 | { 154 | if (top == NULL) 155 | printf("\n**Top is not available for an EMPTY stack**\n"); 156 | else 157 | printf("\nTop of the stack is %d \n",top->data); 158 | } 159 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.7ACF2c: -------------------------------------------------------------------------------- 1 | node growableStackUsingArrays.cpp /^struct node$/;" s file: 2 | data growableStackUsingArrays.cpp /^ int data;$/;" m struct:node file: 3 | link growableStackUsingArrays.cpp /^ struct node *link;$/;" m struct:node typeref:struct:node::node file: 4 | top growableStackUsingArrays.cpp /^}*top = NULL;$/;" v typeref:struct:node 5 | MAX growableStackUsingArrays.cpp 10;" d file: 6 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 7 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 8 | empty growableStackUsingArrays.cpp /^void empty();$/;" p file: 9 | stack_full growableStackUsingArrays.cpp /^void stack_full();$/;" p file: 10 | stack_count growableStackUsingArrays.cpp /^int stack_count();$/;" p file: 11 | destroy growableStackUsingArrays.cpp /^void destroy();$/;" p file: 12 | print_top growableStackUsingArrays.cpp /^void print_top();$/;" p file: 13 | main growableStackUsingArrays.cpp /^int main(){$/;" f 14 | push growableStackUsingArrays.cpp /^void push(){$/;" f 15 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 16 | empty growableStackUsingArrays.cpp /^void empty()$/;" f 17 | stack_full growableStackUsingArrays.cpp /^void stack_full()$/;" f 18 | stack_count growableStackUsingArrays.cpp /^int stack_count()$/;" f 19 | st_count growableStackUsingArrays.cpp /^int st_count()$/;" f 20 | destroy growableStackUsingArrays.cpp /^void destroy()$/;" f 21 | print_top growableStackUsingArrays.cpp /^void print_top()$/;" f 22 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.8eYO3j: -------------------------------------------------------------------------------- 1 | stack growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 2 | choice growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 3 | n growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 4 | top growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 5 | x growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 6 | i growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 7 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 8 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 9 | display growableStackUsingArrays.cpp /^void display();$/;" p file: 10 | main growableStackUsingArrays.cpp /^int main(){$/;" f 11 | push growableStackUsingArrays.cpp /^void push()$/;" f 12 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 13 | display growableStackUsingArrays.cpp /^void display(){$/;" f 14 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.LreEc3: -------------------------------------------------------------------------------- 1 | stack growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 2 | choice growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 3 | n growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 4 | top growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 5 | x growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 6 | i growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 7 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 8 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 9 | display growableStackUsingArrays.cpp /^void display();$/;" p file: 10 | main growableStackUsingArrays.cpp /^int main(){$/;" f 11 | push growableStackUsingArrays.cpp /^void push()$/;" f 12 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 13 | display growableStackUsingArrays.cpp /^void display(){$/;" f 14 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.Oe5Abw: -------------------------------------------------------------------------------- 1 | node growableStackUsingArrays.cpp /^struct node$/;" s file: 2 | data growableStackUsingArrays.cpp /^ int data;$/;" m struct:node file: 3 | link growableStackUsingArrays.cpp /^ struct node *link;$/;" m struct:node typeref:struct:node::node file: 4 | top growableStackUsingArrays.cpp /^}*top = NULL;$/;" v typeref:struct:node 5 | MAX growableStackUsingArrays.cpp 10;" d file: 6 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 7 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 8 | empty growableStackUsingArrays.cpp /^void empty();$/;" p file: 9 | stack_full growableStackUsingArrays.cpp /^void stack_full();$/;" p file: 10 | stack_count growableStackUsingArrays.cpp /^void stack_count();$/;" p file: 11 | destroy growableStackUsingArrays.cpp /^void destroy();$/;" p file: 12 | print_top growableStackUsingArrays.cpp /^void print_top();$/;" p file: 13 | main growableStackUsingArrays.cpp /^int main(){$/;" f 14 | push growableStackUsingArrays.cpp /^void push(){$/;" f 15 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 16 | empty growableStackUsingArrays.cpp /^void empty()$/;" f 17 | stack_full growableStackUsingArrays.cpp /^void stack_full()$/;" f 18 | stack_count growableStackUsingArrays.cpp /^void stack_count()$/;" f 19 | st_count growableStackUsingArrays.cpp /^int st_count()$/;" f 20 | destroy growableStackUsingArrays.cpp /^void destroy()$/;" f 21 | print_top growableStackUsingArrays.cpp /^void print_top()$/;" f 22 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.dJ1jji: -------------------------------------------------------------------------------- 1 | stack growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 2 | choice growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 3 | n growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 4 | top growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 5 | x growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 6 | i growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 7 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 8 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 9 | display growableStackUsingArrays.cpp /^void display();$/;" p file: 10 | main growableStackUsingArrays.cpp /^int main(){$/;" f 11 | push growableStackUsingArrays.cpp /^void push()$/;" f 12 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 13 | display growableStackUsingArrays.cpp /^void display(){$/;" f 14 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.efXjWp: -------------------------------------------------------------------------------- 1 | node growableStackUsingArrays.cpp /^struct node$/;" s file: 2 | data growableStackUsingArrays.cpp /^ int data;$/;" m struct:node file: 3 | link growableStackUsingArrays.cpp /^ struct node *link;$/;" m struct:node typeref:struct:node::node file: 4 | top growableStackUsingArrays.cpp /^}*top = NULL;$/;" v typeref:struct:node 5 | MAX growableStackUsingArrays.cpp 10;" d file: 6 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 7 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 8 | empty growableStackUsingArrays.cpp /^void empty();$/;" p file: 9 | stack_full growableStackUsingArrays.cpp /^void stack_full();$/;" p file: 10 | stack_count growableStackUsingArrays.cpp /^void stack_count();$/;" p file: 11 | destroy growableStackUsingArrays.cpp /^void destroy();$/;" p file: 12 | print_top growableStackUsingArrays.cpp /^void print_top();$/;" p file: 13 | main growableStackUsingArrays.cpp /^int main(){$/;" f 14 | push growableStackUsingArrays.cpp /^void push(){$/;" f 15 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 16 | empty growableStackUsingArrays.cpp /^void empty()$/;" f 17 | stack_full growableStackUsingArrays.cpp /^void stack_full()$/;" f 18 | stack_count growableStackUsingArrays.cpp /^void stack_count()$/;" f 19 | st_count growableStackUsingArrays.cpp /^int st_count()$/;" f 20 | destroy growableStackUsingArrays.cpp /^void destroy()$/;" f 21 | print_top growableStackUsingArrays.cpp /^void print_top()$/;" f 22 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.is3fPk: -------------------------------------------------------------------------------- 1 | stack growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 2 | choice growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 3 | n growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 4 | top growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 5 | x growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 6 | i growableStackUsingArrays.cpp /^int stack[100],choice,n,top,x,i;$/;" v 7 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 8 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 9 | display growableStackUsingArrays.cpp /^void display();$/;" p file: 10 | main growableStackUsingArrays.cpp /^int main(){$/;" f 11 | push growableStackUsingArrays.cpp /^void push()$/;" f 12 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 13 | display growableStackUsingArrays.cpp /^void display(){$/;" f 14 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/GrowableStacksusingArrays/tags.xQqN9s: -------------------------------------------------------------------------------- 1 | node growableStackUsingArrays.cpp /^struct node$/;" s file: 2 | data growableStackUsingArrays.cpp /^ int data;$/;" m struct:node file: 3 | link growableStackUsingArrays.cpp /^ struct node *link;$/;" m struct:node typeref:struct:node::node file: 4 | top growableStackUsingArrays.cpp /^}*top = NULL;$/;" v typeref:struct:node 5 | MAX growableStackUsingArrays.cpp 10;" d file: 6 | push growableStackUsingArrays.cpp /^void push();$/;" p file: 7 | pop growableStackUsingArrays.cpp /^void pop();$/;" p file: 8 | empty growableStackUsingArrays.cpp /^void empty();$/;" p file: 9 | stack_full growableStackUsingArrays.cpp /^void stack_full();$/;" p file: 10 | stack_count growableStackUsingArrays.cpp /^int stack_count();$/;" p file: 11 | destroy growableStackUsingArrays.cpp /^void destroy();$/;" p file: 12 | print_top growableStackUsingArrays.cpp /^void print_top();$/;" p file: 13 | main growableStackUsingArrays.cpp /^int main(){$/;" f 14 | push growableStackUsingArrays.cpp /^void push(){$/;" f 15 | pop growableStackUsingArrays.cpp /^void pop(){$/;" f 16 | empty growableStackUsingArrays.cpp /^void empty()$/;" f 17 | stack_full growableStackUsingArrays.cpp /^void stack_full()$/;" f 18 | stack_count growableStackUsingArrays.cpp /^int stack_count()$/;" f 19 | st_count growableStackUsingArrays.cpp /^int st_count()$/;" f 20 | destroy growableStackUsingArrays.cpp /^void destroy()$/;" f 21 | print_top growableStackUsingArrays.cpp /^void print_top()$/;" f 22 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/InfixToPostfix/InfixToPostfix: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/InfixToPostfix/InfixToPostfix -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/InfixToPostfix/InfixToPostfix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Stack{ 6 | int top; 7 | unsigned capacity; 8 | int* array; 9 | }; 10 | 11 | struct Stack* createStack( unsigned capacity ){ 12 | struct Stack* stack = (struct Stack*) malloc(sizeof(struct Stack)); 13 | 14 | if (!stack) 15 | return NULL; 16 | 17 | stack->top = -1; 18 | stack->capacity = capacity; 19 | 20 | stack->array = (int*) malloc(stack->capacity * sizeof(int)); 21 | 22 | if (!stack->array) 23 | return NULL; 24 | return stack; 25 | } 26 | int isEmpty(struct Stack* stack){ 27 | return stack->top == -1 ; 28 | } 29 | char peek(struct Stack* stack){ 30 | return stack->array[stack->top]; 31 | } 32 | char pop(struct Stack* stack){ 33 | if (!isEmpty(stack)) 34 | return stack->array[stack->top--] ; 35 | return '$'; 36 | } 37 | void push(struct Stack* stack, char op){ 38 | stack->array[++stack->top] = op; 39 | } 40 | 41 | 42 | int isOperand(char ch){ 43 | return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); 44 | } 45 | 46 | int Prec(char ch){ 47 | switch (ch){ 48 | case '+': 49 | case '-': 50 | return 1; 51 | 52 | case '*': 53 | case '/': 54 | return 2; 55 | 56 | case '^': 57 | return 3; 58 | } 59 | return -1; 60 | } 61 | 62 | 63 | int infixToPostfix(char* exp){ 64 | int i, k; 65 | 66 | struct Stack* stack = createStack(strlen(exp)); 67 | if(!stack) 68 | return -1 ; 69 | 70 | for (i = 0, k = -1; exp[i]; ++i){ 71 | 72 | if (isOperand(exp[i])) 73 | exp[++k] = exp[i]; 74 | 75 | else if (exp[i] == '(') 76 | push(stack, exp[i]); 77 | 78 | else if (exp[i] == ')'){ 79 | while (!isEmpty(stack) && peek(stack) != '(') 80 | exp[++k] = pop(stack); 81 | if (!isEmpty(stack) && peek(stack) != '(') 82 | return -1; 83 | else 84 | pop(stack); 85 | } 86 | else{ 87 | while (!isEmpty(stack) && Prec(exp[i]) <= Prec(peek(stack))) 88 | exp[++k] = pop(stack); 89 | push(stack, exp[i]); 90 | } 91 | 92 | } 93 | 94 | while (!isEmpty(stack)) 95 | exp[++k] = pop(stack ); 96 | 97 | exp[++k] = '\0'; 98 | printf( "%sn", exp ); 99 | } 100 | 101 | int main(){ 102 | char exp[] = "a+b*(c^d-e)^(f+g*h)-i"; 103 | infixToPostfix(exp); 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/InfixToPostfix/Screenshot from 2017-09-11 22-35-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/InfixToPostfix/Screenshot from 2017-09-11 22-35-40.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/InfixToPostfix/tags.ImdyM3: -------------------------------------------------------------------------------- 1 | Stack InfixToPostfix.cpp /^struct Stack{$/;" s file: 2 | top InfixToPostfix.cpp /^ int top;$/;" m struct:Stack file: 3 | capacity InfixToPostfix.cpp /^ unsigned capacity;$/;" m struct:Stack file: 4 | array InfixToPostfix.cpp /^ int* array;$/;" m struct:Stack file: 5 | createStack InfixToPostfix.cpp /^struct Stack* createStack( unsigned capacity ){$/;" f 6 | isEmpty InfixToPostfix.cpp /^int isEmpty(struct Stack* stack){$/;" f 7 | peek InfixToPostfix.cpp /^char peek(struct Stack* stack){$/;" f 8 | pop InfixToPostfix.cpp /^char pop(struct Stack* stack){$/;" f 9 | push InfixToPostfix.cpp /^void push(struct Stack* stack, char op){$/;" f 10 | isOperand InfixToPostfix.cpp /^int isOperand(char ch){$/;" f 11 | Prec InfixToPostfix.cpp /^int Prec(char ch){$/;" f 12 | infixToPostfix InfixToPostfix.cpp /^int infixToPostfix(char* exp){$/;" f 13 | main InfixToPostfix.cpp /^int main(){$/;" f 14 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/ReverseElemOfStack/ReverseElemOfStack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/ReverseElemOfStack/ReverseElemOfStack -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/ReverseElemOfStack/ReverseElemOfStack.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int a; 6 | struct node *next; 7 | }; 8 | 9 | void generate(struct node **); 10 | void display(struct node *); 11 | void stack_reverse(struct node **); 12 | void Delete(struct node **); 13 | 14 | int main(){ 15 | struct node *head=NULL; 16 | generate(&head); 17 | printf("\nThe sequence of contents in stack\n"); 18 | display(head); 19 | printf("\nInversing the contents of the stack\n"); 20 | stack_reverse(&head); 21 | printf("\nThe contents in stack after reversal\n"); 22 | display(head); 23 | delete(&head); 24 | return 0; 25 | } 26 | 27 | void stack_reverse(struct node **head){ 28 | struct node *temp, *prev; 29 | if (*head==NULL){ 30 | printf("Stack does not exist\n"); 31 | } 32 | else if ((*head)->next==NULL){ 33 | printf("Single node stack reversal brings no difference\n"); 34 | } 35 | else if ((*head)->next->next==NULL){ 36 | (*head)->next->next=*head; 37 | *head=(*head)->next; 38 | (*head)->next->next=NULL; 39 | } 40 | else{ 41 | prev=*head; 42 | temp=(*head)->next; 43 | *head=(*head)->next->next; 44 | prev->next=NULL; 45 | while ((*head)->next!=NULL){ 46 | temp->next=prev; 47 | prev=temp; 48 | temp=*head; 49 | *head=(*head)->next; 50 | } 51 | temp->next=prev; 52 | (*head)->next=temp; 53 | } 54 | } 55 | 56 | void display(struct node *head){ 57 | if (head!=NULL){ 58 | printf("%d ", head->a); 59 | display(head->next); 60 | } 61 | } 62 | 63 | void generate(struct node **head){ 64 | int num, i; 65 | struct node *temp; 66 | printf("Enter length of list: "); 67 | scanf("%d", &num); 68 | for (i=num; i>0; i--){ 69 | temp=(struct node *)malloc(sizeof(struct node)); 70 | temp->a=i; 71 | if (*head==NULL){ 72 | *head=temp; 73 | (*head)->next=NULL; 74 | } 75 | else{ 76 | temp->next=*head; 77 | *head=temp; 78 | } 79 | } 80 | } 81 | 82 | void Delete(struct node **head){ 83 | struct node *temp; 84 | while (*head!=NULL){ 85 | temp=*head; 86 | *head=(*head)->next; 87 | free(temp); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/ReverseElemOfStack/Screenshot from 2017-09-10 18_12_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/ReverseElemOfStack/Screenshot from 2017-09-10 18_12_46.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/STACK_USING_LINKED_LIST/STACK_USING_LINKED_LIST: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/STACK_USING_LINKED_LIST/STACK_USING_LINKED_LIST -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/STACK_USING_LINKED_LIST/STACK_USING_LINKED_LIST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct node{ 8 | int item; 9 | struct node *next; 10 | }; 11 | 12 | struct node * Insert(struct node *root,int data){ 13 | 14 | struct node *n; 15 | n=(struct node*)malloc(sizeof(struct node)); 16 | n->next=NULL; 17 | n->item=data; 18 | if(root==NULL){ 19 | root=n; 20 | } 21 | else{ 22 | struct node *par; 23 | par=root; 24 | while(par->next!=NULL){ 25 | par=par->next; 26 | } 27 | par->next=n; 28 | } 29 | return(root); 30 | } 31 | 32 | struct node * Delete(struct node *root){ 33 | struct node *p, *q; 34 | p=q=root; 35 | while(p->next!=NULL){ 36 | q=q->next; 37 | p=q->next; 38 | } 39 | q->next=NULL; 40 | printf("Popped Item is :%d\n",p->item); 41 | free(p); 42 | return(root); 43 | } 44 | 45 | struct node* Traverse (struct node *root){ 46 | struct node *tar; 47 | tar=root; 48 | while(tar!=NULL){ 49 | printf("%d ",tar->item); 50 | tar=tar->next; 51 | } 52 | return(root); 53 | } 54 | int main(){ 55 | int choice,data; 56 | struct node *root=NULL; 57 | while(true){ 58 | printf("\nEnter your choice\n1: PUSH\n2: POP\n3: OVERVIEW\n4: EXIT\n"); 59 | scanf("%d",&choice); 60 | printf("\n"); 61 | switch(choice){ 62 | case 1: 63 | printf("Enter Data: "); 64 | scanf("%d",&data); 65 | root=Insert(root,data); 66 | break; 67 | case 2: 68 | root=Delete(root); 69 | break; 70 | case 3: 71 | root=Traverse(root); 72 | break; 73 | case 4: 74 | exit(0); 75 | } 76 | } 77 | return 0; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab6/STACK_USING_LINKED_LIST/Screenshot from 2017-09-10 18_14_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab6/STACK_USING_LINKED_LIST/Screenshot from 2017-09-10 18_14_27.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/IdenticalStacks/IdenticalStacks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab7/IdenticalStacks/IdenticalStacks -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/IdenticalStacks/IdenticalStacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | class stack 6 | { 7 | public: 8 | int arr[100]; 9 | int top; 10 | int start , full ; 11 | int valid; 12 | public: 13 | stack(){ 14 | top = start = -1; 15 | full = 100 ; 16 | valid = 1; 17 | } 18 | void push(int a); 19 | int pop(); 20 | }; 21 | 22 | void stack::push(int a) 23 | { 24 | if(top == full-1 ){ 25 | printf("\n the stack is full cannot enter any more values"); 26 | } 27 | else{ 28 | top++ ; 29 | arr[top] = a ; 30 | } 31 | } 32 | 33 | int stack::pop(){ 34 | int i; 35 | if(top == start) 36 | { 37 | printf("\n the stack is empty"); 38 | printf("\n A garbage value is printed"); 39 | valid = 0; 40 | } 41 | else 42 | { 43 | i = arr[top]; 44 | top--; 45 | valid = 1; 46 | } 47 | if(valid == 1) 48 | { 49 | return i; 50 | } 51 | } 52 | int main() 53 | { 54 | stack s; 55 | char c , i ; 56 | int flag = 1 , count = 0; 57 | printf("\nEnter the number of elements : "); 58 | printf("\nEnter the elements : "); 59 | while(1) 60 | { 61 | fflush(stdin); 62 | printf("\nenter :"); 63 | scanf("%c",&c); 64 | 65 | if( c=='('|| c== '{'|| c== '[') 66 | { 67 | s.push(c); 68 | count++; 69 | } 70 | if( c== ')'|| c== '}' || c==']') 71 | { 72 | i = s.pop(); 73 | count--; 74 | switch(c) 75 | { 76 | case ')': 77 | if( i == '(') 78 | flag = 1; 79 | else 80 | flag = 0; 81 | break; 82 | case '}': 83 | if( i == '{') 84 | flag = 1; 85 | else 86 | flag = 0; 87 | break; 88 | case ']': 89 | if( i == '[') 90 | flag = 1; 91 | else 92 | flag = 0; 93 | break; 94 | } 95 | 96 | 97 | } 98 | if( flag == 0 || c == 'y') 99 | break; 100 | } 101 | if( flag == 0 || count != 0) 102 | printf(" not a valid string"); 103 | else 104 | printf(" a valid string"); 105 | 106 | return 0; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/IdenticalStacks/Screenshot from 2017-09-11 22-28-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab7/IdenticalStacks/Screenshot from 2017-09-11 22-28-57.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/ImplementingStacksusingTwoQueues/ImplementStacksusingTwoQueues: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab7/ImplementingStacksusingTwoQueues/ImplementStacksusingTwoQueues -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/ImplementingStacksusingTwoQueues/ImplementStacksusingTwoQueues.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define QUEUE_EMPTY_MAGIC 0xdeadbeef 4 | 5 | typedef struct _queue_t{ 6 | int *arr; 7 | int rear, front, count, max; 8 | }queue_t; 9 | 10 | queue_t *queue_allocate(int n); 11 | void queue_insert(queue_t * q, int v); 12 | int queue_remove(queue_t * q); 13 | int queue_count(queue_t * q); 14 | int queue_is_empty(queue_t * q); 15 | 16 | void stack_push(queue_t * q, int v){ 17 | queue_insert(q, v); 18 | } 19 | 20 | int stack_pop(queue_t * q){ 21 | int i, n=queue_count(q); 22 | int removed_element; 23 | for(i=0; i<(n-1); i++){ 24 | removed_element=queue_remove(q); 25 | queue_insert(q, removed_element); 26 | } 27 | removed_element=queue_remove(q); 28 | return removed_element; 29 | } 30 | 31 | int stack_is_empty(queue_t * q){ 32 | return queue_is_empty(q); 33 | } 34 | 35 | int stack_count(queue_t * q){ 36 | return queue_count(q); 37 | } 38 | 39 | int queue_count(queue_t * q){ 40 | return q->count; 41 | } 42 | 43 | queue_t * queue_allocate(int n) { 44 | queue_t *queue; 45 | queue=(queue_t*)malloc(sizeof(queue_t)); 46 | if (queue==NULL) 47 | return NULL; 48 | queue->max=n; 49 | queue->arr=(int*)malloc(sizeof(int) * n); 50 | queue->rear=n - 1; 51 | queue->front=n - 1; 52 | return queue; 53 | } 54 | 55 | void queue_insert(queue_t * q, int v){ 56 | if (q->count==q->max) 57 | return; 58 | q->rear=(q->rear + 1) % q->max; 59 | q->arr[q->rear]=v; 60 | q->count++; 61 | } 62 | 63 | int queue_remove(queue_t * q){ 64 | int retval; 65 | if (q->count==0) 66 | return QUEUE_EMPTY_MAGIC; 67 | q->front=(q->front + 1) % q->max; 68 | retval=q->arr[q->front]; 69 | q->count--; 70 | return retval; 71 | } 72 | 73 | int queue_is_empty(queue_t * q){ 74 | return (q->count==0); 75 | } 76 | 77 | void queue_display(queue_t * q){ 78 | int i=(q->front + 1) % q->max, elements=queue_count(q); 79 | while (elements--){ 80 | printf("[%d], ", q->arr[i]); 81 | i=(i>=q->max) ? 0 : (i + 1); 82 | } 83 | } 84 | 85 | int main(){ 86 | queue_t *q; 87 | int x, select; 88 | q=queue_allocate(128); 89 | do 90 | { 91 | printf("\n[1] Push\n[2] Pop\n[0] Exit"); 92 | printf("\nChoice: "); 93 | scanf(" %d", &select); 94 | switch (select) { 95 | case 1: 96 | printf("\nEnter value to Push:"); 97 | scanf(" %d", &x); 98 | stack_push(q, x); 99 | printf("\n\n**********************************\nCurrent Queue:\n"); 100 | queue_display(q); 101 | printf("\n\nPushed Value: %d", x); 102 | printf("\n**********************************\n"); 103 | break; 104 | case 2: 105 | x=stack_pop(q); 106 | printf("\n\n\n\n**********************************\nCurrent Queue:\n"); 107 | queue_display(q); 108 | if (x==QUEUE_EMPTY_MAGIC) 109 | printf("\n\nNo values removed"); 110 | else 111 | printf("\n\nPopped Value: %d", x); 112 | printf("\n**********************************\n"); 113 | break; 114 | case 0: 115 | printf("\nQutting.\n"); 116 | return 0; 117 | default: 118 | printf("\nQutting.\n"); 119 | return 0; 120 | } 121 | }while (1); 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/ImplementingStacksusingTwoQueues/Screenshot from 2017-09-10 18_16_58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab7/ImplementingStacksusingTwoQueues/Screenshot from 2017-09-10 18_16_58.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/PostfixEvaluation/PostfixEvaluation: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab7/PostfixEvaluation/PostfixEvaluation -------------------------------------------------------------------------------- /Sources/Submission 2/lab7/PostfixEvaluation/PostfixEvaluation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int stack[100]; 5 | int top=-1 ; 6 | 7 | void push(int item){ 8 | if(top>=100-1){ 9 | printf("stack overflow"); 10 | return; 11 | } 12 | else{ 13 | top++; 14 | stack[top]=item; 15 | } 16 | } 17 | 18 | int pop(){ 19 | int item; 20 | if(top==-1){ 21 | printf("stack underflow"); 22 | } 23 | else{ 24 | item=stack[top]; 25 | top--; 26 | return item; 27 | } 28 | } 29 | 30 | void EvalPostfix(char postfix[]){ 31 | int i; 32 | char ch; 33 | int val; 34 | int A, B ; 35 | for (i=0 ; postfix[i]!=')'; i++){ 36 | ch=postfix[i]; 37 | if (isdigit(ch)){ 38 | push(ch - '0'); 39 | } 40 | else if (ch=='+' || ch=='-' || ch=='*' || ch=='/'){ 41 | A=pop(); 42 | B=pop(); 43 | switch (ch){ 44 | case '*': 45 | val=B * A; 46 | break; 47 | 48 | case '/': 49 | val=B / A; 50 | break; 51 | 52 | case '+': 53 | val=B + A; 54 | break; 55 | 56 | case '-': 57 | val=B - A; 58 | break; 59 | } 60 | push(val); 61 | } 62 | } 63 | printf( " \n Result of expression evaluation : %d \n", pop()) ; 64 | } 65 | 66 | int main(){ 67 | int i ; 68 | char postfix[100]; 69 | printf("ASSUMPTION: There are only four operators(*, /, +, -) in an expression and operand is single digit only.\n"); 70 | printf( " \nEnter postfix expression,\npress right parenthesis ')' for end expression : "); 71 | for (i=0 ; i<=99; i++){ 72 | scanf("%c", &postfix[i]); 73 | if ( postfix[i]==')' ){ 74 | break; 75 | } 76 | } 77 | EvalPostfix(postfix); 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/GrowableQueuesusingarrays/GrowableQueuesusingarrays: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/GrowableQueuesusingarrays/GrowableQueuesusingarrays -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/GrowableQueuesusingarrays/GrowableQueuesusingarrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 50 4 | 5 | void insert(); 6 | void deletee(); 7 | void display(); 8 | 9 | int queue_array[MAX]; 10 | int rear = - 1; 11 | int front = - 1; 12 | 13 | int main(){ 14 | int choice; 15 | while (1){ 16 | printf("1.Insert element to queue \n"); 17 | printf("2.Delete element from queue \n"); 18 | printf("3.Display all elements of queue \n"); 19 | printf("4.Quit \n"); 20 | printf("Enter your choice : "); 21 | scanf("%d", &choice); 22 | switch (choice){ 23 | case 1: 24 | insert(); 25 | break; 26 | case 2: 27 | deletee(); 28 | break; 29 | case 3: 30 | display(); 31 | break; 32 | case 4: 33 | exit(1); 34 | default: 35 | printf("Wrong choice \n"); 36 | } 37 | } 38 | } 39 | 40 | void insert(){ 41 | int add_item; 42 | if (rear == MAX - 1) 43 | printf("Queue Overflow \n"); 44 | else{ 45 | if (front == - 1) 46 | front = 0; 47 | printf("Inset the element in queue : "); 48 | scanf("%d", &add_item); 49 | rear = rear + 1; 50 | queue_array[rear] = add_item; 51 | } 52 | } 53 | 54 | void deletee(){ 55 | if (front == - 1 || front > rear){ 56 | printf("Queue Underflow \n"); 57 | return ; 58 | } 59 | else{ 60 | printf("Element deleted from queue is : %d\n", queue_array[front]); 61 | front = front + 1; 62 | } 63 | } 64 | 65 | void display(){ 66 | int i; 67 | if (front==-1) 68 | printf("Queue is empty \n"); 69 | else{ 70 | printf("Queue is : \n"); 71 | for (i = front; i <= rear; i++) 72 | printf("%d ", queue_array[i]); 73 | printf("\n"); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/GrowableQueuesusingarrays/Screenshot from 2017-09-11 05_12_56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/GrowableQueuesusingarrays/Screenshot from 2017-09-11 05_12_56.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementDoubleEndedQueues/ImplementDoubleEndedQueues: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/ImplementDoubleEndedQueues/ImplementDoubleEndedQueues -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementDoubleEndedQueues/ImplementDoubleEndedQueues.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef struct dequeue 5 | { 6 | int data[30]; 7 | int rear,front; 8 | }dequeue; 9 | 10 | void initialize(dequeue *p); 11 | int empty(dequeue *p); 12 | int full(dequeue *p); 13 | void enqueueR(dequeue *p,int x); 14 | void enqueueF(dequeue *p,int x); 15 | int dequeueF(dequeue *p); 16 | int dequeueR(dequeue *p); 17 | void print(dequeue *p); 18 | 19 | int main(){ 20 | int i,x,op,n; 21 | dequeue q; 22 | 23 | initialize(&q); 24 | 25 | do{ 26 | printf("\n1.Create\n2.Insert(rear)\n3.Insert(front)\n4.Delete(rear)\n5.Delete(front)"); 27 | printf("\n6.Print\n7.Exit\n\nEnter your choice:"); 28 | scanf("%d",&op); 29 | 30 | switch(op){ 31 | case 1: printf("\nEnter number of elements:"); 32 | scanf("%d",&n); 33 | initialize(&q); 34 | printf("\nEnter the data:"); 35 | 36 | for(i=0;irear=-1; 97 | P->front=-1; 98 | } 99 | 100 | int empty(dequeue *P){ 101 | if(P->rear==-1) 102 | return(1); 103 | 104 | return(0); 105 | } 106 | 107 | int full(dequeue *P){ 108 | if((P->rear+1)%30==P->front) 109 | return(1); 110 | 111 | return(0); 112 | } 113 | 114 | void enqueueR(dequeue *P,int x){ 115 | if(empty(P)){ 116 | P->rear=0; 117 | P->front=0; 118 | P->data[0]=x; 119 | } 120 | else{ 121 | P->rear=(P->rear+1)%30; 122 | P->data[P->rear]=x; 123 | } 124 | } 125 | 126 | void enqueueF(dequeue *P,int x){ 127 | if(empty(P)){ 128 | P->rear=0; 129 | P->front=0; 130 | P->data[0]=x; 131 | } 132 | else{ 133 | P->front=(P->front-1+30)%30; 134 | P->data[P->front]=x; 135 | } 136 | } 137 | 138 | int dequeueF(dequeue *P){ 139 | int x; 140 | x=P->data[P->front]; 141 | if(P->rear==P->front) 142 | initialize(P); 143 | else 144 | P->front=(P->front+1)%30; 145 | 146 | return(x); 147 | } 148 | 149 | int dequeueR(dequeue *P){ 150 | int x; 151 | 152 | x=P->data[P->rear]; 153 | 154 | if(P->rear==P->front) 155 | initialize(P); 156 | else 157 | P->rear=(P->rear-1+30)%30; 158 | 159 | return(x); 160 | } 161 | 162 | void print(dequeue *P){ 163 | if(empty(P)){ 164 | printf("\nQueue is empty!!"); 165 | exit(0); 166 | } 167 | 168 | int i; 169 | i=P->front; 170 | 171 | while(i!=P->rear){ 172 | printf("\n%d",P->data[i]); 173 | i=(i+1)%30; 174 | } 175 | 176 | printf("\n%d\n",P->data[P->rear]); 177 | } 178 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementDoubleEndedQueues/Screenshot from 2017-09-10 18_39_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/ImplementDoubleEndedQueues/Screenshot from 2017-09-10 18_39_16.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementQueuesUsingTwoStacks/ImplementQueuesUsingTwoStacks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/ImplementQueuesUsingTwoStacks/ImplementQueuesUsingTwoStacks -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementQueuesUsingTwoStacks/ImplementQueuesUsingTwoStacks.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | void push(struct node** top, int data); 10 | int pop(struct node** top); 11 | struct queue{ 12 | struct node *stack1; 13 | struct node *stack2; 14 | }; 15 | 16 | void enqueue(struct queue *q, int x){ 17 | push(&q->stack1, x); 18 | } 19 | 20 | void dequeue(struct queue *q){ 21 | int x; 22 | if (q->stack1 == NULL && q->stack2 == NULL) { 23 | printf("queue is empty"); 24 | return; 25 | } 26 | if (q->stack2 == NULL){ 27 | while (q->stack1 != NULL){ 28 | x = pop(&q->stack1); 29 | push(&q->stack2, x); 30 | } 31 | } 32 | x = pop(&q->stack2); 33 | printf("%d\n", x); 34 | } 35 | 36 | void push(struct node** top, int data){ 37 | struct node* newnode = (struct node*) malloc(sizeof(struct node)); 38 | if (newnode == NULL){ 39 | printf("Stack overflow \n"); 40 | return; 41 | } 42 | newnode->data = data; 43 | newnode->next = (*top); 44 | (*top) = newnode; 45 | } 46 | int pop(struct node** top){ 47 | int buff; 48 | struct node *t; 49 | if((*top)== NULL){ 50 | printf("Stack underflow \n"); 51 | return 0; 52 | } 53 | else{ 54 | t = *top; 55 | buff = t->data; 56 | *top = t->next; 57 | free(t); 58 | return buff; 59 | } 60 | } 61 | 62 | void display(struct node *top1,struct node *top2){ 63 | while (top1 != NULL){ 64 | printf("%d\n", top1->data); 65 | top1 = top1->next; 66 | } 67 | while (top2 != NULL){ 68 | printf("%d\n", top2->data); 69 | top2 = top2->next; 70 | } 71 | } 72 | 73 | int main(){ 74 | struct queue *q = (struct queue*)malloc(sizeof(struct queue)); 75 | int f = 0, a; 76 | char ch = 'y'; 77 | q->stack1 = NULL; 78 | q->stack2 = NULL; 79 | while (ch == 'y'||ch == 'Y') { 80 | printf("Enter your choice\n1.add to queue\n2.remove from queue\n3.display\n4.exit\n"); 81 | scanf("%d", &f); 82 | switch(f){ 83 | case 1 : printf("enter the element to be added to queue\n"); 84 | scanf("%d", &a); 85 | enqueue(q, a); 86 | break; 87 | case 2 : dequeue(q); 88 | break; 89 | case 3 : display(q->stack1, q->stack2); 90 | break; 91 | case 4 : exit(1); 92 | break; 93 | default : printf("invalid\n"); 94 | break; 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/ImplementQueuesUsingTwoStacks/Screenshot from 2017-09-11 05_17_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/ImplementQueuesUsingTwoStacks/Screenshot from 2017-09-11 05_17_47.png -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/QueueusingsingleLL/QueueusingsingleLL: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/QueueusingsingleLL/QueueusingsingleLL -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/QueueusingsingleLL/QueueusingsingleLL.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node{ 5 | int data; 6 | struct Node *next; 7 | }*front = NULL,*rear = NULL; 8 | 9 | void insert(int); 10 | void deletee(); 11 | void display(); 12 | 13 | int main(){ 14 | int choice, value; 15 | printf("\n:: Queue Implementation using Linked List ::\n"); 16 | while(1){ 17 | printf("\n****** MENU ******\n"); 18 | printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n"); 19 | printf("Enter your choice: "); 20 | scanf("%d",&choice); 21 | switch(choice){ 22 | case 1: printf("Enter the value to be insert: "); 23 | scanf("%d", &value); 24 | insert(value); 25 | break; 26 | case 2: deletee(); break; 27 | case 3: display(); break; 28 | case 4: return 0; 29 | default: printf("\nWrong selection!!! Please try again!!!\n"); 30 | } 31 | } 32 | } 33 | void insert(int value){ 34 | struct Node *newNode; 35 | newNode = (struct Node*)malloc(sizeof(struct Node)); 36 | newNode->data = value; 37 | newNode -> next = NULL; 38 | if(front == NULL) 39 | front = rear = newNode; 40 | else{ 41 | rear -> next = newNode; 42 | rear = newNode; 43 | } 44 | printf("\nInsertion is Success!!!\n"); 45 | } 46 | void deletee(){ 47 | if(front == NULL) 48 | printf("\nQueue is Empty!!!\n"); 49 | else{ 50 | struct Node *temp = front; 51 | front = front -> next; 52 | printf("\nDeleted element: %d\n", temp->data); 53 | free(temp); 54 | } 55 | } 56 | void display(){ 57 | if(front == NULL) 58 | printf("\nQueue is Empty!!!\n"); 59 | else{ 60 | struct Node *temp = front; 61 | while(temp->next != NULL){ 62 | printf("%d--->",temp->data); 63 | temp = temp -> next; 64 | } 65 | printf("%d--->NULL\n",temp->data); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Sources/Submission 2/lab8/QueueusingsingleLL/Screenshot from 2017-09-11 05_20_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 2/lab8/QueueusingsingleLL/Screenshot from 2017-09-11 05_20_48.png -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q1/Screenshot from 2017-11-02 08-09-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q1/Screenshot from 2017-11-02 08-09-43.png -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q1/q1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q1/q1 -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q1/q1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct AdjListNode 5 | { 6 | int dest; 7 | struct AdjListNode* next; 8 | }; 9 | 10 | struct AdjList 11 | { 12 | struct AdjListNode *head; 13 | }; 14 | 15 | struct Graph 16 | { 17 | int V; 18 | struct AdjList* array; 19 | }; 20 | 21 | struct AdjListNode* newAdjListNode(int dest) 22 | { 23 | struct AdjListNode* newNode = 24 | (struct AdjListNode*) malloc(sizeof(struct AdjListNode)); 25 | newNode->dest = dest; 26 | newNode->next = NULL; 27 | return newNode; 28 | } 29 | struct Graph* createGraph(int V) 30 | { 31 | struct Graph* graph = (struct Graph*) malloc(sizeof(struct Graph)); 32 | graph->V = V; 33 | 34 | graph->array = (struct AdjList*) malloc(V * sizeof(struct AdjList)); 35 | 36 | int i; 37 | for (i = 0; i < V; ++i) 38 | graph->array[i].head = NULL; 39 | 40 | return graph; 41 | } 42 | void addEdge(struct Graph* graph, int src, int dest) 43 | { 44 | struct AdjListNode* newNode = newAdjListNode(dest); 45 | newNode->next = graph->array[src].head; 46 | graph->array[src].head = newNode; 47 | 48 | newNode = newAdjListNode(src); 49 | newNode->next = graph->array[dest].head; 50 | graph->array[dest].head = newNode; 51 | } 52 | void printGraph(struct Graph* graph) 53 | { 54 | int v; 55 | for (v = 0; v < graph->V; ++v) 56 | { 57 | struct AdjListNode* pCrawl = graph->array[v].head; 58 | printf("\n Adjacency list of vertex %d\n head ", v); 59 | while (pCrawl) 60 | { 61 | printf("-> %d", pCrawl->dest); 62 | pCrawl = pCrawl->next; 63 | } 64 | printf("\n"); 65 | } 66 | } 67 | 68 | int main(){ 69 | int V = 5; 70 | struct Graph* graph = createGraph(V); 71 | addEdge(graph, 0, 1); 72 | addEdge(graph, 0, 4); 73 | addEdge(graph, 1, 2); 74 | addEdge(graph, 1, 3); 75 | addEdge(graph, 1, 4); 76 | addEdge(graph, 2, 3); 77 | addEdge(graph, 3, 4); 78 | printGraph(graph); 79 | 80 | return 0; 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q2/Screenshot from 2017-11-02 08-10-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q2/Screenshot from 2017-11-02 08-10-55.png -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q2/q2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q2/q2 -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q2/q2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define initial 1 5 | #define waiting 2 6 | #define visited 3 7 | 8 | int n; 9 | int adj[50][50]; 10 | int state[50]; 11 | void create_graph(); 12 | void BF_Traversal(); 13 | void BFS(int v); 14 | 15 | int queue[50], front = -1,rear = -1; 16 | void insert_queue(int vertex); 17 | int delete_queue(); 18 | int isEmpty_queue(); 19 | 20 | int main() 21 | { 22 | create_graph(); 23 | BF_Traversal(); 24 | return 0; 25 | } 26 | 27 | void BF_Traversal(){ 28 | int v; 29 | 30 | for(v=0; v rear) 79 | return 1; 80 | else 81 | return 0; 82 | } 83 | 84 | int delete_queue() 85 | { 86 | int delete_item; 87 | if(front == -1 || front > rear) 88 | { 89 | printf("Queue Underflow\n"); 90 | exit(1); 91 | } 92 | 93 | delete_item = queue[front]; 94 | front = front+1; 95 | return delete_item; 96 | } 97 | 98 | void create_graph() 99 | { 100 | int count,max_edge,origin,destin; 101 | 102 | printf("Enter number of vertices : "); 103 | scanf("%d",&n); 104 | max_edge = n*(n-1); 105 | 106 | for(count=1; count<=max_edge; count++) 107 | { 108 | printf("Enter edge %d( -1 -1 to quit ) : ",count); 109 | scanf("%d %d",&origin,&destin); 110 | 111 | if((origin == -1) && (destin == -1)) 112 | break; 113 | 114 | if(origin>=n || destin>=n || origin<0 || destin<0) 115 | { 116 | printf("Invalid edge!\n"); 117 | count--; 118 | } 119 | else 120 | { 121 | adj[origin][destin] = 1; 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q3/Screenshot from 2017-11-02 08-12-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q3/Screenshot from 2017-11-02 08-12-11.png -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q3/q3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Graphs/Q3/q3 -------------------------------------------------------------------------------- /Sources/Submission 3/Graphs/Q3/q3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void DFS(int); 4 | int G[10][10],visited[10], n; 5 | 6 | int main(){ 7 | int i,j; 8 | printf("Enter number of vertices:"); 9 | scanf("%d",&n); 10 | printf("\nEnter adjecency matrix of the graph:"); 11 | for(i=0;i 2 | #include 3 | #include 4 | 5 | struct Edge{ 6 | int src, dest; 7 | }; 8 | 9 | struct Graph{ 10 | int V, E; 11 | struct Edge* edge; 12 | }; 13 | 14 | struct Graph* createGraph(int V, int E){ 15 | struct Graph* graph = 16 | (struct Graph*) malloc( sizeof(struct Graph) ); 17 | graph->V = V; 18 | graph->E = E; 19 | 20 | graph->edge = 21 | (struct Edge*) malloc(graph->E*sizeof(struct Edge)); 22 | 23 | return graph; 24 | } 25 | 26 | int find(int parent[], int i){ 27 | if (parent[i] == -1) 28 | return i; 29 | return find(parent, parent[i]); 30 | } 31 | 32 | void Union(int parent[], int x, int y){ 33 | int xset = find(parent, x); 34 | int yset = find(parent, y); 35 | parent[xset] = yset; 36 | } 37 | 38 | int isCycle( struct Graph* graph ){ 39 | int *parent = (int*) malloc( graph->V * sizeof(int) ); 40 | 41 | memset(parent, -1, sizeof(int) * graph->V); 42 | 43 | for(int i = 0; i < graph->E; ++i) 44 | { 45 | int x = find(parent, graph->edge[i].src); 46 | int y = find(parent, graph->edge[i].dest); 47 | 48 | if (x == y) 49 | return 1; 50 | 51 | Union(parent, x, y); 52 | } 53 | return 0; 54 | } 55 | 56 | int main(){ 57 | int V = 3, E = 3; 58 | struct Graph* graph = createGraph(V, E); 59 | 60 | graph->edge[0].src = 0; 61 | graph->edge[0].dest = 1; 62 | 63 | graph->edge[1].src = 1; 64 | graph->edge[1].dest = 2; 65 | 66 | graph->edge[2].src = 0; 67 | graph->edge[2].dest = 2; 68 | 69 | if (isCycle(graph)) 70 | printf( "graph contains cycle" ); 71 | else 72 | printf( "graph doesn't contain cycle" ); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q1/Screenshot from 2017-11-02 14-12-15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q1/Screenshot from 2017-11-02 14-12-15.png -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q1/q1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q1/q1 -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q1/q1.c: -------------------------------------------------------------------------------- 1 | //Josephus problem 2 | #include 3 | 4 | int josephus(int n, int k){ 5 | if(n==1) 6 | return 1; 7 | else 8 | return (josephus(n-1, k)+k-1)%n+1; 9 | } 10 | 11 | int main(){ 12 | int n=20; 13 | int k=2; 14 | printf("The chosen place is %d", josephus(n, k)); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q1/tags.n9NQfo: -------------------------------------------------------------------------------- 1 | josephus q1.c /^int josephus(int n, int k){$/;" f 2 | main q1.c /^int main(){$/;" f 3 | -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q2/Screenshot from 2017-11-01 23-07-34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q2/Screenshot from 2017-11-01 23-07-34.png -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q2/cubed: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q2/cubed -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q2/cubed.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | long long int c, u, b, e, d; 4 | for(c=0; c<=9; c++){ 5 | for(u=0; u<=9; u++){ 6 | for(b=0; b<=9; b++){ 7 | for(e=0; e<=9; e++){ 8 | for(d=0; d<=9; d++){ 9 | if((c+u+b+e+d)*(c+u+b+e+d)*(c+u+b+e+d)==(d+e*10+b*100+u*1000+c*10000)) 10 | printf("The solution is c=%lld u=%lld b=%lld e=%lld d=%lld\n",c,u,b,e,d); 11 | } 12 | } 13 | } 14 | } 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q3/Q3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q3/Q3.png -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q3/q3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Miscellaneous/Q3/q3 -------------------------------------------------------------------------------- /Sources/Submission 3/Miscellaneous/Q3/q3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(){ 4 | int normstack[100], minstack[100]; 5 | int top=-1; int dop=-1; int count=0; int CurrentMin; 6 | int choice; int data; 7 | while(1){ 8 | printf("\n1: Push\t2: Pop\t3: Get-minimum\t4: Exit\n"); 9 | scanf("%d",&choice); 10 | switch(choice){ 11 | case 1: 12 | printf("Enter Data to Push: "); 13 | scanf("%d", &data); 14 | normstack[++top]= data; 15 | if(count==0){ 16 | minstack[++dop]= data; 17 | CurrentMin=data; 18 | } 19 | else if(data 2 | 3 | void calculateSpan(int price[], int n, int S[]){ 4 | S[0] = 1; 5 | for (int i = 1; i < n; i++){ 6 | S[i] = 1; 7 | for (int j = i-1; (j>=0)&&(price[i]>=price[j]); j--) 8 | S[i]++; 9 | } 10 | } 11 | int main(){ 12 | int price[] = {100, 120, 40, 35, 55, 36}; 13 | int n = sizeof(price)/sizeof(price[0]); 14 | int S[n]; 15 | 16 | calculateSpan(price, n, S); 17 | for (int i = 0; i < n; i++) 18 | printf("%d ", S[i]); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Insertion sort/Screenshot from 2017-11-01 13-59-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Sorting/Insertion sort/Screenshot from 2017-11-01 13-59-55.png -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Insertion sort/insertionsort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Sorting/Insertion sort/insertionsort -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Insertion sort/insertionsort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void insertion_sort(int arr[], int n); 4 | int main(){ 5 | int arr[500], i, n; 6 | printf("Enter the number of elements in the array: "); 7 | scanf("%d", &n); 8 | printf("\nEnter the elements of the array: "); 9 | for(i=0;i=0)){ 24 | arr[j+1]=arr[j]; 25 | j--; 26 | } 27 | arr[j+1]=temp; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Insertion sort/tags.6f7LY8: -------------------------------------------------------------------------------- 1 | insertion_sort insertionsort.c /^void insertion_sort(int arr[], int n);$/;" p file: 2 | main insertionsort.c /^int main(){$/;" f 3 | insertion_sort insertionsort.c /^void insertion_sort(int arr[], int n){$/;" f 4 | -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Insertion sort/tags.dwMi4j: -------------------------------------------------------------------------------- 1 | insertion_sort insertionsort.c /^void insertion_sort(int arr[], int n);$/;" p file: 2 | main insertionsort.c /^int main(){$/;" f 3 | insertion_sort insertionsort.c /^void insertion_sort(int arr[], int n){$/;" f 4 | -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Merge sort/Merge sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Sorting/Merge sort/Merge sort.png -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Merge sort/mergesort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Sorting/Merge sort/mergesort -------------------------------------------------------------------------------- /Sources/Submission 3/Sorting/Merge sort/mergesort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge(int a[], int, int, int); 4 | void sort(int a[],int, int); 5 | 6 | int main(){ 7 | int arr[1000], i, n; 8 | printf("\n Enter the number of elements in the array : "); 9 | scanf("%d", &n); 10 | printf("\n Enter the elements of the array: "); 11 | for(i=0;imid){ 35 | while(j<=high){ 36 | temp[index]=arr[j]; 37 | j++; 38 | index++; 39 | } 40 | } 41 | else{ 42 | while(i<=mid){ 43 | temp[index]=arr[i]; 44 | i++; 45 | index++; 46 | } 47 | } 48 | for(k=low;k 2 | 3 | int partition(int a[], int low, int high); 4 | void quick_sort(int a[], int low, int high); 5 | 6 | int main(){ 7 | int arr[1000], i, n; 8 | printf("Enter the number of elements in the array: "); 9 | scanf("%d", &n); 10 | printf("\nEnter the elements of the array: "); 11 | for(i=0;ia[right]){ 31 | temp=a[loc]; 32 | a[loc]=a[right]; 33 | a[right]=temp; 34 | loc=right; 35 | } 36 | if(flag!=1){ 37 | while((a[loc] >= a[left]) && (loc!=left)) 38 | left++; 39 | if(loc==left) 40 | flag =1; 41 | else if(a[loc] 2 | 3 | int largest(int arr[], int n); 4 | void radix_sort(int arr[], int n); 5 | 6 | int main(){ 7 | int arr[1000], i, n; 8 | printf("\n Enter the number of elements in the array: "); 9 | scanf("%d", &n); 10 | printf("\n Enter the elements of the array: "); 11 | for(i=0;ilarge) 24 | large=arr[i]; 25 | } 26 | return large; 27 | } 28 | void radix_sort(int arr[], int n){ 29 | int bucket[1000][1000], bucket_count[1000]; 30 | int i, j, k, remainder, NOP=0, divisor=1, large, pass; 31 | large=largest(arr, n); 32 | while(large>0){ 33 | NOP++; 34 | large/=1000; 35 | } 36 | for(pass=0;pass 2 | #include 3 | 4 | int smallest(int arr[], int k, int n); 5 | void selection_sort(int arr[], int n); 6 | int main(){ 7 | int arr[500], i, n; 8 | printf("Enter the number of elements in the array: "); 9 | scanf("%d", &n); 10 | printf("\nEnter the elements of the array: "); 11 | for(i=0;i 3 | #include 4 | 5 | int levelorder[50], size; 6 | 7 | void display(){ 8 | printf("The binary tree in level order as inserted was :\n"); 9 | for(int i=0; i=index; i--) 18 | levelorder[i+1]=levelorder[i]; 19 | levelorder[index]=data; 20 | return; 21 | } 22 | void delete(int data){ 23 | int i=0, count=0; 24 | for(int j=0; j: \n"); 48 | while(1){ 49 | scanf("%d",&element); 50 | if(element==0) 51 | break; 52 | else 53 | levelorder[i++]=element; 54 | } 55 | size=i; 56 | display(); 57 | printf("Inserting value 5 at index 2, the tree will become as: \n"); 58 | insert(2, 5); 59 | display(); 60 | printf("Deleting element 5.........\n"); 61 | delete(5); 62 | display(); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q2/Screenshot from 2017-11-01 18-34-42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q2/Screenshot from 2017-11-01 18-34-42.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q2/q2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q2/q2 -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q2/q2.c: -------------------------------------------------------------------------------- 1 | //store binary tree in a linked list 2 | #include 3 | #include 4 | 5 | struct node{ 6 | int data; 7 | struct node *left; 8 | struct node *right; 9 | }; 10 | struct node *insert(int data){ 11 | struct node* temp=(struct node *)malloc(sizeof(struct node)); 12 | temp->data=data; 13 | temp->left=NULL; 14 | temp->right=NULL; 15 | return temp; 16 | } 17 | void inorder(struct node* root){ 18 | if(root==NULL){ 19 | return; 20 | } 21 | else{ 22 | inorder(root->left); 23 | printf("%d\t",root->data); 24 | inorder(root->right); 25 | } 26 | } 27 | void preorder(struct node* root){ 28 | if(root==NULL){ 29 | return; 30 | } 31 | else{ 32 | printf("%d\t",root->data); 33 | preorder(root->left); 34 | preorder(root->right); 35 | } 36 | } 37 | int main(){ 38 | struct node *root=insert(5); 39 | root->left=insert(3); 40 | root->right=insert(6); 41 | (root->left)->left=insert(2); 42 | (root->left)->right=insert(3); 43 | printf("The data of ((root->left)->left) is %d\n",((root->left)->left)->data); 44 | inorder(root); 45 | printf("\n"); 46 | preorder(root); 47 | printf("\n"); 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q3/Screenshot from 2017-11-01 18-35-55.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q3/Screenshot from 2017-11-01 18-35-55.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q3/q3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q3/q3 -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q3/q3.c: -------------------------------------------------------------------------------- 1 | //finding an element of binary search tree in array representation given its key 2 | #include 3 | #include 4 | 5 | int levelorder[50], size; 6 | void display(){ 7 | printf("The binary tree in level order as inserted was :\n"); 8 | for(int i=0; i=index; i--) 17 | levelorder[i+1]=levelorder[i]; 18 | levelorder[index]=data; 19 | return; 20 | } 21 | void delete(int data){ 22 | int i=0, count=0; 23 | for(int j=0; j: \n"); 46 | while(1){ 47 | scanf("%d",&element); 48 | if(element==0) 49 | break; 50 | else 51 | levelorder[i++]=element; 52 | } 53 | size=i; 54 | } 55 | void search(int key){ 56 | int k=0, counter=0; 57 | while(k 3 | #include 4 | 5 | struct node{ 6 | int data; 7 | struct node *left; 8 | struct node *right; 9 | }; 10 | struct node* newnode(int data){ 11 | struct node* temp=(struct node*)malloc(sizeof(struct node)); 12 | temp->data=data; 13 | temp->left=NULL; 14 | temp->right=NULL; 15 | return temp; 16 | } 17 | struct node* insert(struct node* root, int data){ 18 | if(root==NULL){ 19 | root=newnode(data); 20 | return root; 21 | } 22 | else{ 23 | if(data<=(root->data)){ 24 | root->left=insert(root->left, data); 25 | } 26 | else{ 27 | root->right=insert(root->right, data); 28 | } 29 | } 30 | return root; 31 | } 32 | struct node *search(struct node* temp, int key){ 33 | if(temp==NULL||temp->data==key){ 34 | return temp; 35 | } 36 | else{ 37 | if(temp->data>key) 38 | search(temp->left, key); 39 | else 40 | search(temp->right, key); 41 | } 42 | } 43 | int main(){ 44 | int sea, insertdata, rootdata; 45 | struct node* temp; 46 | struct node* root=NULL; 47 | printf("Enter the root data of BST: "); 48 | scanf("%d",&rootdata); 49 | root=insert(root, rootdata); 50 | do{ 51 | printf("Enter the data to enter in the BST<0 to stop>: "); 52 | scanf("%d",&insertdata); 53 | insert(root, insertdata); 54 | }while(insertdata!=0); 55 | printf("Enter the element to search in the BST:\n"); 56 | scanf("%d",&sea); 57 | temp=search(root, sea); 58 | if(temp==NULL) 59 | printf("Data not found\n"); 60 | else 61 | printf("Element found: %d\n",temp->data); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q5/Screenshot from 2017-11-01 19-02-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q5/Screenshot from 2017-11-01 19-02-40.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q5/q5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q5/q5 -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q5/q5.c: -------------------------------------------------------------------------------- 1 | //Program to find maximum depth of a BST 2 | #include 3 | #include 4 | 5 | struct node{ 6 | int data; 7 | struct node* left; 8 | struct node* right; 9 | }; 10 | struct node* newnode(int data){ 11 | struct node* Node=(struct node *)malloc(sizeof(struct node)); 12 | Node->data=data; 13 | Node->left=NULL; 14 | Node->right=NULL; 15 | return Node; 16 | } 17 | struct node* insert(struct node* root, int data){ 18 | if(root==NULL){ 19 | root=newnode(data); 20 | return root; 21 | } 22 | else{ 23 | if(data<=(root->data)){ 24 | root->left=insert(root->left, data); 25 | } 26 | else{ 27 | root->right=insert(root->right, data); 28 | } 29 | } 30 | return root; 31 | } 32 | int maxdepth(struct node* root){ 33 | int rdepth, ldepth; 34 | if(root==NULL){ 35 | return 0; 36 | } 37 | else{ 38 | rdepth=maxdepth(root->right); 39 | ldepth=maxdepth(root->left); 40 | if(rdepth>ldepth){ 41 | return (rdepth+1); 42 | } 43 | else{ 44 | return (ldepth+1); 45 | } 46 | } 47 | } 48 | int main(){ 49 | int option, data; 50 | struct node* root=NULL; 51 | do{ 52 | printf("1. Insert\t2. Find Maxdepth\t3. Exit\n"); 53 | printf("Enter the option: "); 54 | scanf("%d",&option); 55 | switch(option){ 56 | case 1: 57 | printf("\nEnter the data to enter in BST: "); 58 | scanf("%d",&data); 59 | root=insert(root, data); 60 | break; 61 | case 2: 62 | printf("The maximum depth of the BST is: %d\n", maxdepth(root)); 63 | break; 64 | case 3: 65 | return 0; 66 | default: 67 | printf("Err... Please enter correct option !!!\n"); 68 | } 69 | }while(option!=3); 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/Q6_NR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q6/Q6_NR.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/q6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q6/q6 -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/q6.c: -------------------------------------------------------------------------------- 1 | //Traverse BST in inorder, pre and post-order using recursion 2 | #include 3 | #include 4 | 5 | struct node{ 6 | int data; 7 | struct node* left; 8 | struct node* right; 9 | }; 10 | struct node* newnode(int data){ 11 | struct node* Node=(struct node *)malloc(sizeof(struct node)); 12 | Node->data=data; 13 | Node->left=NULL; 14 | Node->right=NULL; 15 | return Node; 16 | } 17 | struct node* insert(struct node* root, int data){ 18 | if(root==NULL){ 19 | root=newnode(data); 20 | return root; 21 | } 22 | else{ 23 | if(data<=(root->data)){ 24 | root->left=insert(root->left, data); 25 | } 26 | else{ 27 | root->right=insert(root->right, data); 28 | } 29 | } 30 | return root; 31 | } 32 | void inorder(struct node* root){ 33 | if(root==NULL){ 34 | return; 35 | } 36 | else{ 37 | inorder(root->left); 38 | printf("%d\t",root->data); 39 | inorder(root->right); 40 | } 41 | } 42 | void preorder(struct node* root){ 43 | if(root==NULL){ 44 | return; 45 | } 46 | else{ 47 | printf("%d\t",root->data); 48 | preorder(root->left); 49 | preorder(root->right); 50 | } 51 | } 52 | void postorder(struct node* root){ 53 | if(root==NULL){ 54 | return; 55 | } 56 | else{ 57 | preorder(root->left); 58 | preorder(root->right); 59 | printf("%d\t",root->data); 60 | } 61 | } 62 | int main(){ 63 | struct node *root=NULL; 64 | int rootdata, insertdata; 65 | printf("Enter the root data for BST: "); 66 | scanf("%d",&rootdata); 67 | root=insert(root, rootdata); 68 | do{ 69 | printf("Enter the data to insert in BST<0 to exit>: "); 70 | scanf("%d",&insertdata); 71 | root=insert(root, insertdata); 72 | }while(insertdata!=0); 73 | printf("The Inorder traversal of BST is\n"); 74 | inorder(root); 75 | printf("\nThe Pre-order traversal of BST is\n"); 76 | preorder(root); 77 | printf("\nThe Post-order traversal of BST is\n"); 78 | postorder(root); 79 | printf("\n"); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/q6NR: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q6/q6NR -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/q6NR.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node* left; 7 | struct node* right; 8 | }; 9 | 10 | struct node* root=NULL; 11 | struct node* current; 12 | 13 | struct node stack[100]; 14 | int top=-1; 15 | 16 | void push(struct node data){ 17 | if(top==99){ 18 | printf("stack overflow!\n"); 19 | return; 20 | } 21 | else{ 22 | top++; 23 | stack[top]=data; 24 | } 25 | } 26 | int pop(){ 27 | struct node* key; 28 | if(top==-1){ 29 | printf("stack underflow\n"); 30 | return 0; 31 | } 32 | else{ 33 | key=&stack[top]; 34 | top--; 35 | } 36 | return (key->data); 37 | } 38 | struct node* popstack(){ 39 | struct node* key=&stack[top]; 40 | top--; 41 | return key; 42 | } 43 | int isempty(){ 44 | if(top==-1){ 45 | return 1; 46 | } 47 | else{ 48 | return 0; 49 | } 50 | } 51 | struct node* newnode(int data){ 52 | struct node* temp=(struct node*)malloc(sizeof(struct node)); 53 | temp->data=data; 54 | temp->left=NULL; 55 | temp->right=NULL; 56 | return temp; 57 | } 58 | 59 | struct node* insert(struct node* root, int data){ 60 | if(root==NULL){ 61 | root=newnode(data); 62 | return root; 63 | } 64 | else{ 65 | if(data<=root->data){ 66 | root->left=insert(root->left, data); 67 | } 68 | else{ 69 | root->right=insert(root->right, data); 70 | } 71 | return root; 72 | } 73 | } 74 | 75 | void inorder(struct node *root){ 76 | struct node *p; 77 | p=root; 78 | printf("The In-order traversal of BST is:\n"); 79 | while(1){ 80 | while(p!=NULL){ 81 | top++; 82 | stack[top]=*p; 83 | p=p->left; 84 | } 85 | if(top==-1) 86 | break; 87 | p=&stack[top]; 88 | top--; 89 | printf("%d\t",p->data); 90 | p=p->right; 91 | } 92 | } 93 | void preorder(struct node *root){ 94 | int flag=0; 95 | struct node *p=root; 96 | printf("The Pre-order traversal of BST is:\n"); 97 | while(1){ 98 | while(p!=NULL){ 99 | printf("%d\t",p->data); 100 | top++; 101 | stack[top]=*p; //push element onto stack 102 | if(p->left==NULL && p->right==NULL) 103 | flag=1; //if left child is present for current node set flag to 1 104 | p=p->left; 105 | } 106 | if(flag==1) //leaf node has been inserted into stack it so pop it out 107 | { 108 | p=&stack[top]; 109 | top--; 110 | flag=0; 111 | } 112 | if(top==-1) 113 | break; 114 | p=&stack[top]; //get parent node from stack 115 | top--; 116 | p=p->right; //now traverse to the right of parent 117 | } 118 | } 119 | void postorder(struct node* root){ 120 | if(root==NULL) 121 | return; 122 | do{ 123 | while(root){ 124 | if (root->right) 125 | push(*root->right); 126 | push(*root); 127 | root = root->left; 128 | } 129 | root=popstack(); 130 | if(root->right && popstack() == root->right){ 131 | pop(); // remove right child from stack 132 | push(*root); // push root back to stack 133 | root = root->right; // change root so that the right 134 | } 135 | else{ 136 | printf("%d ", root->data); 137 | root = NULL; 138 | } 139 | } while (!isempty()); 140 | } 141 | int main(){ 142 | int insertdata, choice; 143 | do{ 144 | printf("\nEnter the data to insert in BST<0 to exit>: "); 145 | scanf("%d",&insertdata); 146 | root=insert(root, insertdata); 147 | }while(insertdata!=0); 148 | do{ 149 | printf("1. In-order\t2. Pre-order\t3. Post-order\t4. Exit\n"); 150 | printf("Enter your choice: "); 151 | scanf("%d",&choice); 152 | switch(choice){ 153 | case 1: 154 | inorder(root); 155 | printf("\n"); 156 | break; 157 | case 2: 158 | preorder(root); 159 | printf("\n"); 160 | break; 161 | case 3: 162 | postorder(root); 163 | printf("\n"); 164 | break; 165 | case 4: 166 | return 0; 167 | default: 168 | printf("Err. Please enter correct choice.\n"); 169 | break; 170 | } 171 | }while(choice!=4); 172 | return 0; 173 | } 174 | -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q6/q6_RECURSIVE.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q6/q6_RECURSIVE.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q7/Screenshot from 2017-11-01 21-49-56.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q7/Screenshot from 2017-11-01 21-49-56.png -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q7/q7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jishanshaikh4/CSE-217-Data-Structures-Laboratory/d75babdf1e5bc923310a45cc243de493ad358ba3/Sources/Submission 3/Trees/Q7/q7 -------------------------------------------------------------------------------- /Sources/Submission 3/Trees/Q7/q7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int arr[500]; 4 | struct node{ 5 | int data; 6 | struct node* left; 7 | struct node* right; 8 | }; 9 | struct node* root=NULL; 10 | struct node* newnode(int data){ 11 | struct node* temp=(struct node*)malloc(sizeof(struct node)); 12 | temp->data=data; 13 | temp->left=NULL; 14 | temp->right=NULL; 15 | return temp; 16 | } 17 | struct node* insert(struct node* root, int data){ 18 | if(root==NULL){ 19 | root=newnode(data); 20 | return root; 21 | } 22 | else{ 23 | if(data<=root->data){ 24 | root->left=insert(root->left, data); 25 | } 26 | else{ 27 | root->right=insert(root->right, data); 28 | } 29 | return root; 30 | } 31 | } 32 | void inorder(struct node* root){ 33 | if(root==NULL){ 34 | return; 35 | } 36 | else{ 37 | inorder(root->left); 38 | printf("%d\t",root->data); 39 | inorder(root->right); 40 | } 41 | } 42 | int main(){ 43 | int i,n; 44 | printf("Enter the size of array: "); 45 | scanf("%d",&n); 46 | printf("\nEnter the elements of unsorted array :\n"); 47 | for(i=0; i