100% found this document useful (8 votes)
54 views

PDF C Data Structures A Laboratory Course Stefan Brandle download

Laboratory

Uploaded by

morylrandtoy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (8 votes)
54 views

PDF C Data Structures A Laboratory Course Stefan Brandle download

Laboratory

Uploaded by

morylrandtoy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Download the full version of the ebook at ebookname.

com

C Data Structures A Laboratory Course Stefan


Brandle

https://ebookname.com/product/c-data-structures-a-
laboratory-course-stefan-brandle/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Data Structures Using C 2nd Edition A. K. Sharma

https://ebookname.com/product/data-structures-using-c-2nd-edition-a-k-
sharma/

ebookname.com

C Plus Data Structures Third Edition Nell Dale

https://ebookname.com/product/c-plus-data-structures-third-edition-
nell-dale/

ebookname.com

ADTs Data Structures and Problem Solving with C 2nd


Edition Nyhoff

https://ebookname.com/product/adts-data-structures-and-problem-
solving-with-c-2nd-edition-nyhoff/

ebookname.com

Solar to Chemical Conversion Photocatalytic and


Photoelectrochemical Processes 1st Edition Hongqi Sun
(Editor)
https://ebookname.com/product/solar-to-chemical-conversion-
photocatalytic-and-photoelectrochemical-processes-1st-edition-hongqi-
sun-editor/
ebookname.com
An Introduction to Tensegrity Anthony Pugh

https://ebookname.com/product/an-introduction-to-tensegrity-anthony-
pugh/

ebookname.com

Public Services Issues with Rare and Archival Law


Materials 1st Edition Michael Widener

https://ebookname.com/product/public-services-issues-with-rare-and-
archival-law-materials-1st-edition-michael-widener/

ebookname.com

John Paul II on the Vulnerable 1st Edition Jeffrey


Tranzillo

https://ebookname.com/product/john-paul-ii-on-the-vulnerable-1st-
edition-jeffrey-tranzillo/

ebookname.com

Militant Right Wing Extremism in Putin s Russia Legacies


Forms and Threats Jan Holzer

https://ebookname.com/product/militant-right-wing-extremism-in-putin-
s-russia-legacies-forms-and-threats-jan-holzer/

ebookname.com

Congress The First Branch Benjamin Ginsberg

https://ebookname.com/product/congress-the-first-branch-benjamin-
ginsberg/

ebookname.com
Managing People in Entrepreneurial Organizations Advances
in Entrepreneurship Firm Emergence and Growth Advances in
Entrepreneurship Firm Emergence Entrepreneurship Firm
Emergence and Growth 1st Edition Jerome A. Katz
https://ebookname.com/product/managing-people-in-entrepreneurial-
organizations-advances-in-entrepreneurship-firm-emergence-and-growth-
advances-in-entrepreneurship-firm-emergence-entrepreneurship-firm-
emergence-and-growth-1st-editi/
ebookname.com
++ Third Edition
C
Data Structures
A Laboratory Course

Stefan Brandle
Taylor University

Jonathan Geisler
Taylor University

James Robergé

David Whittington
Filtro Systems, Inc.

JONES AND BARTLETT PUBLISHERS


Sudbury, Massachusetts
BOSTON TORONTO LONDON SINGAPORE
World Headquarters
Jones and Bartlett Publishers
40 Tall Pine Drive
Sudbury, MA 01776
978-443-5000
info@jbpub.com
www.jbpub.com
Jones and Bartlett Publishers Canada
6339 Ormindale Way
Mississauga, Ontario L5V 1J2
Canada
Jones and Bartlett Publishers International
Barb House, Barb Mews
London W6 7PA
United Kingdom

Jones and Bartlett's books and products are available through most bookstores and online booksellers.
To contact Jones and Bartlett Publishers directly, call 800-832-0034, fax 978-443-8000, or visit our website
www.jbpub.com.

Substantial discounts on bulk quantities of Jones and Bartlett's publications are available to
corporations, professional associations, and other qualified organizations. For details and specific discount
information, contact the special sales department at Jones and Bartlett via the above contact information or
send an email to specialsales@jbpub.com.

Copyright © 2009 by Jones and Bartlett Publishers, LLC

ISBN-13: 978-0-7637-5564-5

All rights reserved. No part of the material protected by this copyright may be reproduced or utilized in
any form, electronic or mechanical, including photocopying, recording, or by any information storage and
retrieval system, without written permission from the copyright owner.

Production Credits
Acquisitions Editor: Tim Anderson
Production Director: Amy Rose
Editorial Assistant: Melissa Elmore
Senior Marketing Manager: Andrea DeFronzo
Manufacturing Buyer: Therese Connell
Composition: Northeast Compositors
Cover Design: Kate Ternullo
Cover Image: © Cocota Anca/ShutterStock, Inc.
Printing and Binding: Courier Stoughton
Cover Printing: Courier Stoughton

6048
Printed in the United States of America
12 11 10 09 08 10 9 8 7 6 5 4 3 2 1
To Christina, Anna, and Esther, for giving me the time to work on this.
—Stefan Brandle

To the women in my life. Thanks for the great deal of understanding with so
little payback time.
—Jonathan Geisler

To Michael, for letting me share in his creativity.


—James Robergé

To my family and to Melissa.


—David Whittington
contents
Preface

1 Text ADT
Focus: Implement an ADT using a C++ class, introduce a number of
foundational C++ concepts used in ADT implementation, and an
array implementation of a delimited character string
Application: Lexical analysis

2 BlogEntry ADT
Focus: Implement a blog entry class and continue introduction of
foundational C++ concepts used in ADT implementation
Application: Generate an HTML representation of a data structure's contents

3 Array Implementation of the List ADT


Focus: Array implementation of a list
Application: Analyzing DNA sequences

4 Ordered List ADT


Focus: Array implementation of an ordered list using inheritance
Application: Assembling messages in a packet switching network

5 Singly Linked List Implementation of the List ADT


Focus: Singly linked list implementation of a list
Application: Slide show program

6 Stack ADT
Focus: Array and singly linked list implementations of a stack
Application: Evaluating postfix arithmetic expressions

7 Queue ADT
Focus: Array and singly linked list implementations of a queue
Application: Simulating the flow of customers through a line

8 Expression Tree ADT


Focus: Linked implementation of an expression tree
Application: Logic circuits

9 Binary Search Tree ADT


Focus: Linked implementation of a binary search tree
Application: Indexed accounts database

10 Hash Table ADT


Focus: Hash table implementation with chaining
Application: Development of a perfect hash

11 Heap ADT
Focus: Array implementation of a heap
Application: Simulating the flow of tasks in an operating system using a
priority queue

12 Weighted Graph ADT


Focus: Adjacency matrix implementation of the Weighted Graph ADT
Application: Computation of shortest paths

13 Performance Evaluation
Focus: Determining execution times
Application: Analyzing the execution times of sorting and searching routines
preface
Preface to the Third Edition

We have used James Robergé's laboratory manual for eight years at Taylor
University. The approach and style of the original manual made it an extremely
effective teaching tool. In 2002, we were given the privilege of updating the first
edition to reflect changes in C++ and to add some new material.
It is now time for a third edition. Perhaps most significantly, all the worksheet
pages—which comprised a high percentage of the book—were moved into a set
of online supplements that instructors and students can print as needed. The
appendix material is now widely available online from multiple sources.
We discovered that many of those using the book are now using it for more
advanced courses such as Data Structures and Algorithms. A major reason for
this is that many universities have switched the second computer science course
(CS2, sometimes also called Data Structures) from C++ to Java. Given that the
target audience has shifted somewhat, and that students using the lab book have
probably already encountered Object-Oriented Programming, we chose to
increase the level of C++ and data structure sophistication. However, we ensured
that the book is still very usable for CS2—which is where we continue to use it.
Aspects of the second edition were out of date because of changes in the C++
language. Also, compilers have caught up enough with newer C++ standards that
we can safely use some of the features that either did not exist previously, or
were not reliably supported by enough common compilers. For example, the use
of typename instead of class in templates.
Our goal to be true to Jim Robergé's original vision of the laboratory
experience remains, but we also recognize that the book is no longer necessarily
used with the classic closed lab. As a consequence, we modified our
nomenclature. For instance, In-Lab Exercises are now called Programming
Exercises. Post-Lab Exercises are now called Analysis Exercises. These can still
be used as in-lab/post-lab exercises with a closed lab, but the naming more
accurately reflects the reality that these labs can be used equally well as regular
weekly programming assignments in a non-laboratory course.

Overview of Changes

Each chapter has been organized into Objectives, ADT Overview, C++
Concepts Overview, ADT Specification, Implementation Notes, Compilation
Directions, and Testing. Then, there are three Programming Exercises and two
Analysis Exercises.
We also made the following significant changes:

• Introduced a configuration file, config.h, that allows students to control


which ADT extensions are used by the test program. We feel that this
method is cleaner and a better example for students than the laborious
uncommenting and recommenting that was required.

• Error handling is streamlined: bad_alloc exceptions have been removed.

• The word class in templates has been replaced by the new keyword
typename. The keyword typename is intuitively more self-explanatory
and is not as overloaded as class.

• For the linked data structures where we had external “Node” classes, they
have become inner classes. Although inner classes add a small amount of
syntax, it gets away from the issues of forward declarations for mutually
referring classes. This represents better object-oriented design and we
avoid the use of declaring class friends.

• Copy constructors and overloaded assignment operators are now required


for every ADT implementation.

• The isFull operation has been removed from linked data structures where
it is not required for compatibility with the array-based version. We do
this because determining whether dynamic memory is exhausted is a
fruitless and inefficient exercise. In reality, C++ provides an exception
mechanism to deal with this issue.

• More sophisticated use of templates is presented. Template specialization


is introduced in the Expression Tree. Default template types and template
parameters are introduced in the Heap.

• Lab order has been changed to be compatible with the order in the largest
number of current textbooks. The singly-linked list was moved up to Lab
5 right after the two array-based lists; the expression tree is now before
the binary search tree; the string lab was moved to Lab 1; and the
BlogEntry ADT—the only new lab—is Lab 2.

Note: We still do not use STL in this book (except for one example in the
Performance Analysis lab). However, the STL implementation of a data structure
could be substituted for the student's implementation in necessary situations.

To the Student

Objectives

The courses that we enjoyed most when we were students were those that
emphasized design. In design-oriented courses, we used the concepts taught to
solve practical problems. The process of applying ideas made it easier to
understand them and their application in a real-world setting.
This emphasis on learning by doing is used throughout this book. In each
laboratory, you will explore a particular data structure by implementing it. As
you create an implementation, you will learn how the data structure works and
how it can be applied. The resulting implementation is a working piece of
software that you can later use in laboratories and programming projects.

Organization of the Laboratories

Each laboratory consists of three parts: Basic Implementation and Testing,


Programming Exercises, and Analysis Exercises. The Basic Implementation
section explains the specific Abstract Data Type (ADT), introduces the new C++
concepts, describes the ADT's properties, explains implementation details that
you need to know, and then guides you through testing your implementation. In
the three Programming Exercises, the first exercise is usually to apply the data
structure you created to the solution of a problem. The remaining two exercises
usually apply or extend the concepts introduced in the Basic Implementation.
The last part of each laboratory, the Analysis Exercise, is an assignment in which
you analyze a data structure in terms of its efficiency or use.
Your instructor will specify which exercises you need to complete for each
laboratory and when they are due. You are encouraged to use the cover sheet
provided with the online laboratory worksheets to keep track of the exercises
you have been assigned. Implementation testing is very important—probably
just as important a step as implementing the ADT—and should not be skipped.

Student Resources

The authors have compiled a set of worksheets, interactive tools to test and
debug your work, and “starter kits” containing data, partial solution shells, and
other supporting routines for each of your labs. These tools are available for
download at the Jones and Bartlett lab book website
http://www.jbpub.com/catalog/9780763755645.

To the Instructor

Objectives

When James Robergé was first given the opportunity to introduce


laboratories into his data structures course, he jumped at the chance. He saw
laboratories as a way of involving students as active, creative partners in the
learning process. By making the laboratories the focal point of the course, he
sought to immerse his students in the course material. The goal of each lab is
still to challenge students to exercise their creativity (in both programming and
analysis) while at the same time providing the structure, feedback, and support
that they need to meet the challenge. This manual is the product of years of
experimentation and refinement working toward this objective.

Organization of the Laboratories

In the initial development of these labs, an attempt was made to shoehorn the
creative process into a series of two-hour laboratories. The result was a pressure
cooker that challenged everyone, but helped no one. In experimenting with
solutions to this problem, James Robergé developed a laboratory framework that
retains the creative element but shifts the time-intensive aspects outside the
laboratory period. Within this structure, each laboratory includes three parts:
Basic Implementation and Testing, Programming Exercises, and Analysis
Exercises.
The Basic Implementation section explains the specific Abstract Data Type
(ADT), introduces the new C + + concepts, describes the ADT's properties,
explains implementation details that the student needs to know, and then guides
the student through testing his/her implementation. In the three Programming
Exercises, the first exercise is usually to apply the data structure to the solution
of a problem. The remaining two exercises usually apply or extend the concepts
introduced in the Basic Implementation. The last part of each laboratory, the
Analysis Exercise, is an assignment which analyzes a data structure in terms of
its efficiency or use.

Basic Implementation
The Basic Implementation exercise is intended as a homework assignment
that links the lecture with the laboratory period. Students explore and create on
their own and at their own pace. Their goal is to synthesize the information they
learn in lectures with material from their textbook to produce a working piece of
software, usually an implementation of an abstract data type (ADT). The
implementation assignment— including a review of the relevant lecture and
textbook materials—typically takes four to five hours to complete. We have tried
to include all necessary discussions of new C++ material, implementation
details, special compilation directions, and testing instructions. You should give
students specific instructions for compilation in your laboratory environment.
An interactive, command-driven test program is provided for each laboratory,
along with a text-based visualization routine that allows students to see changes
in the content and organization of a data structure. This part of the assignment
provides an opportunity for students to receive feedback on their basic
implementation and to resolve any difficulties they might have encountered. It
should take students approximately one hour to finish this exercise. Students are
often tempted to skimp on the testing, resulting in poorly implemented
submissions. Requiring students to complete and submit the test plans in the
online worksheets can significantly improve the quality of submissions.

Programming Exercises
This section takes place during the actual laboratory period (assuming you
are using a closed laboratory setting). Each lab contains three exercises, and each
exercise has a distinct role. In Exercise 1, students apply the software they
developed in the Basic Implementation to a real-world problem that has been
honed to its essentials to fit comfortably within the closed laboratory
environment. The last two exercises stress programming by extending the data
structure, and provide a capstone to the basic implementation. Exercise 1 can be
completed in approximately one and a half hours. Exercises 2 and 3 can take as
much as one hour each to complete, but students who did the initial work
thoroughly have a better understanding and can finish more quickly.
Most students will not be able to complete all these programming exercises
within a typical closed laboratory period. We have provided a range of exercises
so that you can select those that best suit your laboratory environment and your
students' needs.

Analysis Exercises
The last phase of each laboratory is a set of two homework assignments in
which students analyze the efficiency or utility of a given data structure. Each
Analysis Exercise should take roughly thirty minutes to complete. Assuming a
closed laboratory structure, one or both could be done following the laboratory
period.

Using the Three-Part Organization in Your Laboratory


Environment

The term laboratory is used by computer science instructors to denote a


broad range of environments. One group of students in a data structures course,
for example, may attend a closed two-hour laboratory; at the same time, another
group of students may take the class in a televised format and “attend” an open
laboratory. In developing this manual, we have preserved the first edition's
efforts to create a laboratory format suitable for a variety of open and closed
laboratory settings. How you use the organization depends on your laboratory
environment.

Two-Hour Closed Laboratory

Basic Implementation
We expect the students attending a two-hour closed laboratory to make a
good-faith effort to complete the basic implementation exercise before coming to
the lab. Their work need not be perfect, but their effort must be real (roughly
80% correct). We ask our students to complete the test plans and to begin testing
and debugging their implementation work prior to coming to lab (as part of the
80% correct guideline).

Programming Exercises
We use the first hour of the laboratory period to resolve any problems the
students might have experienced in completing the Basic Implementation and
Testing. Our intention is to give constructive feedback so that students leave the
lab with a working implementation—a significant accomplishment on their part.
During the second hour, we have students complete one of the programming
exercises in order to reinforce the concepts learned in the basic implementation.
You can choose the exercise by section or by student, or you can let the students
decide which one to complete.
Students leave the lab having received feedback on their basic implementation
and additional programming exercise work. You need not rigidly enforce the
hourly divisions; a mix of activities keeps everyone interested and motivated.

Analysis Exercises
After the lab, the students complete one (or both) of the analysis exercises
and turn it in during their next lab period.

One-Hour Closed Laboratory

Basic Implementation
If we have only one hour for the closed laboratory, we ask students to
complete all of the Basic Implementation and Testing before they come to the
lab. This work is turned in at the start of the period.

Programming Exercises
During the laboratory period, the students complete one of the additional
programming exercises.
Analysis Exercises
Again, the students complete one or both of the analysis exercises and
submit it during their next lab period.

Open Laboratory

In an open laboratory setting, we have the students complete the Basic


Implementation and Testing exercises, one of the additional programming
exercises, and one or both of the analysis exercises. You can stagger the
submission of these exercises throughout the week or have students turn in the
entire laboratory as a unit.

Student Preparation

This manual assumes that students have a background in either Java or C++.
The first laboratory introduces classes and the use of classes to implement a
simple ADT. Succeeding laboratories introduce more complex C++ language
features (dynamic memory allocation, templates, inheritance, and so forth) in the
context of data structures that use these features.

Order of Topics

All instructors cover the course material in the order that they believe best
suits their students' needs. To give instructors flexibility in the order of
presentation, we have made the individual laboratories as independent of one
another as possible. At a minimum, we recommend beginning with the following
sequence of laboratories:

Laboratory 1 (Text ADT)


Introduces the implementation of an ADT using C++ classes and a
number of foundational features, including constructors, destructors, basic
dynamic memory allocation, and operator overloading. Depending on the
student background, you may choose to implement this over the course of
two weeks.

Laboratory 2 (BlogEntry ADT)


Continues the overview of significant C++ features. Introduces member
initialization, exceptions, static methods, class composition, and extending
iostream functionality.

Laboratory 3 (Array Implementation of the List ADT)


Introduces templates and prepares students for inheritance.

Laboratory 5 (Singly-Linked Implementation of the List ADT)


Introduces linked lists and inner classes.

We have placed the performance evaluation laboratory at the end of the book
(Laboratory 13), because in our experience, we have found that everyone covers
this topic at a different time. Rather than bury it in the middle of the manual, we
have placed it at the end so that you can include it where it best serves you and
your students' needs, be that early in the semester, in the middle, or toward the
end.

ADT Implementation

The laboratories are designed to complement a variety of approaches to


implementing each ADT. All ADT definitions stress the use of data abstraction
and generic data elements. As a result, you can adapt them with minimal effort
to suit different implementation strategies.
For each ADT, class declarations that frame an implementation of the ADT
are given as part of the corresponding basic implementation exercise. This
declaration framework is also used in the visualization function that
accompanies the laboratory. Should you elect to adopt a somewhat different
implementation strategy, you need only make minor changes to the data
members in the class declarations and corresponding modifications to the
visualization routine. You do not need to change anything else in either the
supplied software or the laboratory text itself.

Differences Between the Manual and Your Text

We have found that variations in style between the approaches used in the
textbook and the laboratory manual discourage students from simply copying
material from the textbook. Having to make changes, however slight, encourages
them to examine in more detail how a given implementation works.
Exploring the Variety of Random
Documents with Different Content
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.

You might also like