ebook img

C & Data Structures [Deshpande & Kakde 2004-01 PDF

695 Pages·2008·8.14 MB·English
by  
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C & Data Structures [Deshpande & Kakde 2004-01

ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html C & Data Structures P. S. Deshpande O. G. Kakde CHARLES RIVER MEDIA, INC. Hingham, Massachusetts Copyright © 2003 Dreamtech Press Reprint Copyright © 2004 by CHARLES RIVER MEDIA, INC. All rights reserved. No part of this publication may be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means or media, electronic or mechanical, including, but not limited to, photocopy, recording, or scanning, without prior permission in writing from the publisher. Acquisitions Editor: James Walsh Production: Dreamtech Press Cover Design: Sherry Stinson CHARLES RIVER MEDIA, INC. 10 Downer Avenue Hingham, Massachusetts 02043 781-740-0400 781-740-8816 (FAX) [email protected] http://www.charlesriver.com Page 1 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html P.S. Deshpande and O.G. Kakde. C & Data Structures 1-58450-338-6 All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others. The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. Library of Congress Cataloging-in-Publication Data Deshpande, P. S. C & data structures / P.S. Deshpande, O.G. Kakde. p. cm. ISBN 1-58450-338-6 (Paperback with CD-ROM : alk. paper) 1. C (Computer program language) 2. Data structures (Computer science) I. Kakde, O. G. II. Title. QA76.73.C15D48 2003 005.7'3—dc22 2003021572 04 7 6 5 4 3 2 First Edition CHARLES RIVER MEDIA titles are available for site license or bulk purchase by institutions, user groups, corporations, etc. For additional information, please contact the Special Sales Department at 781-740-0400. Requests for replacement of a defective CD-ROM must be accompanied by the original disc, your mailing address, telephone number, date of purchase and purchase price. Please state the nature of the problem, and send the information to CHARLES RIVER MEDIA, INC., 10 Downer Avenue, Hingham, Massachusetts 02043. CRM's sole obligation to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not on the operation or functionality of the product. Acknowledgments Writing any book is not an easy task. We spent about one year designing the contents, implementing the programs and testing the programs. Our 12 years of teaching experience has helped us to explain the issues in the language and complex problems in data structures. We are thankful to our student Rupesh Nasre who, after receiving an M.Tech. degree in computer science from IIT Mumbai, helped us in implementing advanced problems in data structures. We are also thankful to our students Ms. Usha Agrawal and Mr. Ramchandra Vibhute for helping us in writing programs for II. Page 2 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html C & Data Structures byP.S. DeshpandeandO.G. Kakde ISBN:1584503386 Charles River Media 2004 (700 pages) This thorough text provides a comprehensive guide to all the data types in C with internal implementation, while providing examples to demonstrate their behavior. Table of Contents C & Data Structures Preface Part I - C Language Chapte - Introduction to the C Language r 1 Chapte - Data Types r 2 Chapte - C Operators r 3 Chapte - Control Structures r 4 Chapte - The printf Function r 5 Chapte - Address and Pointers r 6 Chapte - The scanf Function r 7 Chapte - Preprocessing r 8 Chapte - Arrays r 9 Chapte - Function r 10 Chapte - Storage of Variables r 11 Chapte - Memory Allocation r 12 Chapte - Recursion r 13 Chapte - Strings r 14 Chapte - Structures r 15 Chapte - Union r 16 Chapte - Files r 17 Part II - Data Structures Chapte - Arrays, Searching, and Sorting Page 3 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html r 18 Chapte - Stacks and Queues r 19 Chapte - Linked Lists r 20 Chapte - Trees r 21 Chapte - Graphs r 22 Part III - Advanced Problems in Data Structures Chapte - Problems in Arrays, Searching, Sorting, Hashing r 23 Chapte - Problems in Stacks and Queues r 24 Chapte - Problems in Linked Lists r 25 Chapte - Problems in Strings r 26 Chapte - Problems in Trees r 27 Chapte - Problems in Graphs r 28 Chapte - Miscellaneous Problems r 29 Index List of Figures List of Tables Back Cover CD Content Page 4 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Preface The book is written for both undergraduate and graduate students of core computer science areas. The book would be very useful for other students to learn programming for the purpose of making a career in computer science. It covers all those topics that generally appear in aptitude tests and interviews. It not only gives the language syntax but also discusses its behavior by showing the internal implementation. We have covered almost the entire range of data structures and programming such as non-recursive implementation of tree traversals, A* algorithm in Artificial Intelligence, 8-queens problems, etc. We also have supplied a CD-ROM which contains all the source material that appears in the book. We welcome comments from our readers. Page 5 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Part I: C Language Chapter 1: Introduction to the C Language Chapter 2: Data Types Chapter 3: C Operators Chapter 4: Control Structures Chapter 5: The printf Function Chapter 6: Address and Pointers Chapter 7: The scanf Function Chapter 8: Preprocessing Chapter 9: Arrays Chapter 10: Functions Chapter 11: Storage of Variables Chapter 12: Memory Allocation Chapter 13: Recursion Chapter 14: Strings Chapter 15: Structures Chapter 16: Union Chapter 17: Files Page 6 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Chapter 1: Introduction to the C Language THE FIRST PROGRAM IN C Introduction The C program is a set of functions. The program execution begins by executing the function main (). You can compile the program and execute using Turbo C compiler or using the following commands in Unix/Linux: $ cc -o a a.c where a.c is the file in which you have written the program. This will create an executable file named a.exe. $./a. This will execute the program. Program #include <stdio.h> main() { printf("Hello \n"); /* prints Hello on standard output */ } Output : Hello Explanation 1. The program execution begins with the function main(). 2. The executable statements are enclosed within a block that is marked by ‘{’ and ‘}’. 3. The printf() function redirects the output to a standard output, which in most cases is the output on screen. 4. Each executable statement is terminated by ‘;’ 5. The comments are enclosed in ‘/*...*/’ Variables Introduction When you want to process some information, you can save the values temporarily in variables. In the following program you can define two variables, save the values, and put the addition in the third variable. Program #include <stdio.h> main() { int i,j,k; // Defining variables Statement A i = 6; // Statement B j = 8; k = i + j; Page 7 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html printf("sum of two numbers is %d \n",k); // Printing results } output : sum of two numbers is 14 Explanation 1. Statement A defines variables of the type integer. For each variable you have to attach some data type. The data type defines the amount of storage allocated to variables, the values that they can accept, and the operations that can be performed on variables. 2. The ‘ // ’ is used as single line comment. 3. The ‘%d’ is used as format specifier for the integer. Each data type has a format specifier that defines how the data of that data type will be printed. 4. The assignment operator is ‘=’ and the statement is in the format: Var = expression; Points to Remember 1. The variables are defined at the begining of the block. 2. The data type is defined at the begining of declaration and followed by a list of variables. 3. It is the data type that assigns a property to a variable. Page 8 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html INPUTTING THE DATA Introduction In C, the input from a standard input device, such as a keyboard, is taken by using the function scanf. In scanf, you have to specify both the variables in which you can take input, and the format specifier, such as %d for the integer. Program #include <stdio.h> main() { int i,j,k; scanf("%d%d",&i,&j); // statement A k = i + j; printf("sum of two numbers is %d \n",k); } Input 3 4 Output: sum of two numbers is 7 Explanation 1. Statement A indicates the scanf statement that is used for taking input. In scanf you have to specify a list of addresses of variables (&i, &j) which can take input. Before specifying the list of variables you have to include a list of format specifiers that indicate the format of the input. For example, for the integer data type the format specifier is %d. 2. In scanf, you have to specify the address of the variable, such as &i. The address is the memory location where a variable is stored. The reason you must specify the address will be discussed later. 3. The number of format specifiers must be the same as the number of variables. Point to Remember In scanf, you have to specify the address of a variable, such as &i, &j, and a list of format specifiers. Page 9 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html THE CONTROL STATEMENT (if STATEMENT) Introduction You can conditionally execute statements using the if or the if...else statement. The control of the program is dependent on the outcome of the Boolean condition that is specified in the if statement. Program #include <stdio.h> main() { int i,j,big; //variable declaration scanf("%d%d",&i,&j); big = i; if(big < j) // statement A { // C big = j; // Part Z, then part } // D printf("biggest of two numbers is %d \n",big); if(i < j) // statement B { big = j; // Part X } else { big = i; // Part Y } printf("biggest of two numbers(using else) is %d \n",big); } Explanation 1. Statement A indicates the if statement. The general form of the if statement is if(expr) 2. 3. { 4. s1 ; 5. s2 ; 6. .... 7. } 8. expr is a Boolean expression that returns true (nonzero) or false (zero). 9. In C, the value nonzero is true while zero is taken as false. 10. If you want to execute only one statement, opening and closing braces are not required, which is indicated by C and D in the current program. 11. The else part is optional. If the if condition is true then the part that is enclosed after the if is executed (Part X). If the if condition is false then the else part is executed (Part Y). 12. Without the else statement (in the first if statement), if the condition is true then Part Z is executed. Points to Remember 1. if and if...else are used for conditional execution. After the if statement the control is Page 10

Description:
3. It is the data type that assigns a property to a variable. Page 8. ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.