Types of Containers: Sequences
|
|
- Neil Leonard
- 5 years ago
- Views:
Transcription
1 Types of Containers: Sequences
2 Bag vs. Sequence Both contain items Sequence: items are arranged in sequence and order matters Bag: items are arranged in sequence but order does not matter See deletion operation
3 Internal Iterators Iterator: An object that permits the programmer to traverse a container Internal Iterator: a technique to use member functions of a container to traverse the container External Iterator: objects offered by the Standard Library to traverse a container.
4 Sequence typedef value_type sequence::value_type is the data type of the items in the sequence. It may be any of the C++ built-in types (int, char, etc.), or a class with a default constructor, an assignment operator, and a copy constructor. typedef size_type sequence::size_type is the data type of any variable that keeps track of how many items are in a sequence. static const size_type CAPACITY = the maximum number of items that a sequence can hold. CONSTRUCTOR for the sequence class: sequence( ) Postcondition: The sequence has been initialized as an empty sequence.
5 Modification member functions void start( ) /* Postcondition: The first item on the sequence becomes the current item (but if the sequence is empty, then there is no current item). */ void advance( ) // Precondition: is_item returns true. /* Postcondition: If the current item was already the last item in the sequence, then there is no longer any current item. Otherwise, the new current item is the item immediately after the original current item. */
6 Modification member functions void insert(const value_type& entry) // Precondition: size( ) < CAPACITY. /* Postcondition: A new copy of entry has been inserted in the sequence before the current item. If there was no current item, then the new entry has been inserted at the front of the sequence. In either case, the newly inserted item is now the current item of the sequence.*/ To maintain the order - (Pseudocode implementation) for (i= used; i>index_current_item; ; ++i) data[i] = data[i-1]
7 An Example of Calling Insert in Bag void bag::insert(int new_entry) We make a function call b.insert(17) at position i b.data b.count [ 0 ] [ 1 ] [2] What values will be in b.data and b.count after the member function finishes?
8 An Example of Calling Insert in Bag void bag::insert(int new_entry) b.data b.count [ 0 ] [ 1 ] [2] After calling b.insert(17), we will have this bag b: [ 0 ] [1] [ 2 ]
9 An Example of Calling Insert in Sequence void bag::insert(int sequence::insert(int new_entry) new_entry, ) We make a function call seq.insert(17) current_index=1 seq.data seq.count [ 0 ] [ 1 ] [2] What values will be in seq.data and seq.count after the member function finishes?
10 An Example of Calling Insert in Bag void bag::insert(int sequence::insert(int new_entry) new_entry) seq.data seq.count [ 0 ] [ 1 ] [2] After calling seq.insert(17), we will have this bag b: [ 0 ] [1] [ 2 ]
11 Modification member functions void remove_current( ) // Precondition: is_item returns true. /* Postcondition: The current item has been removed from the sequence, and the item after this (if there is one) is now the new current item.*/ What is the pseudocode?
12 Modification member functions void attach(const value_type& entry) // Precondition: size( ) < CAPACITY. /* Postcondition: A new copy of entry has been inserted in the sequence after the current item. If there was no current item, then the new entry has been attached to the end of the sequence. In either case, the newly inserted item is now the current item of the sequence.*/
13 Set and multiset The set class stores elements without repetition The multiset class stores elements with repetition and strict weak ordering (for efficient implementation) Strict weak ordering (<) Irreflexivity: if x=y, then neither (x<y) nor (y<x) is true ( x<x is never true) Antisymmetry: if x and y are not equal, then either (x<y) or (y<x) is true, but not both. Transitivity: Whenever there are 3 values (x, y, and z) with (x<y) and (y<z0, then (x< z) is also true.
14 Multiset members similar to Bag multiset<int> first; first.insert(8); first.insert(4); first.insert(8); The multiset will contain two 8 and one 4 in the order inserted. size_type count(const value_type& target) const; size_type erasevalue_type& target); size_type size();
15 Insert Member function iterator insert(const value_type& entry); STL member functions begin() // returns an iterator providing access to the first item in the container multiset<string>::iterator role; role = actors.begin();
16 The * operator Once a program has created an iterator, the *(asterisk) operator can be used to access the current element. cout << *role << endl; Attention: the iterator is NOT a pointer, but the * operator is used (similarly to a pointer) to get the item in the current position.
17 The ++ operator Once a program has created an iterator, the ++ operator can be used to move the iterator forward. ++role; //returns the first iterator after it has already moved forward Or role++; // returns the iterator before it has moved forward
18 Insert Member function More STL member functions end() // returns an iterator to mark the end of an item. Once it reached the end it has already gone beyond the last item of the container and the * operator must not be used anymore because there are no items.
19 Examining a sequence for (i=c.begin(); i!=c.end(); ++i) {..statements to access the item *i } Left-Inclusive Pattern [ ): The for loop iterates through a set of values at begin() and going up (but not including) the end() value
20 Changing the container multiset<int> m; multiset<int>:: iterator position; position = m.find(24); if (position!= m.end()) m.erase(position) ATTENTION: There are cases when changing a container object causes the invalidation of its iterators. Example: the position iterator is invalid after its item is erased
21 An Example of Calling Insert void bag::insert(int new_entry) We make a function call b.insert(17) b.data b.count [ 0 ] [ 1 ] [2] What values will be in b.data and b.count after the member function finishes?
22 An Example of Calling Insert void bag::insert(int new_entry) b.data b.count [ 0 ] [ 1 ] [2] After calling b.insert(17), we will have this bag b: [ 0 ] [1] [ 2 ]
23 Pseudocode for bag::insert assert(size( ) < CAPACITY); Place new_entry in the appropriate location of the data array. Add one to the member variable count. data[count] = new_entry; count++;
24 Pseudocode for bag::insert assert(size( ) < CAPACITY); Place new_entry in the appropriate location of the data array. Add one to the member variable count. data[ count++] = new_entry;
25 The Other Bag Operations Read Section 3.1 for the implementations of the other bag member functions. Remember: If you are just using the bag class, then you don t need to know how the operations are implemented. Later we will reimplement the bag using more efficient algorithms. We ll also have a few other operations to manipulate bags.
26 Other Kinds of Bags In this example, we have implemented a bag containing integers. But we could have had a bag of float numbers, a bag of characters, a bag of strings... Suppose you wanted one of these other bags. How much would you need to change in the implementation? Section 3.1 gives a simple solution using the C++ typedef statement.
27 Summary A container class is a class that can hold a collection of items. Container classes can be implemented with a C++ class. The class is implemented with a header file (containing documentation and the class definition) and an implementation file (containing the implementations of the member functions). Other details are given in Section 3.1, which you should read.
28 Presentation copyright 2010, Addison Wesley Longman For use with Data Structures and Other Objects Using C++ by Michael Main and Walter Savitch. Some artwork in the presentation is used with permission from Presentation Task Force (copyright New Vision Technologies Inc.) and Corel Gallery Clipart Catalog (copyright Corel Corporation, 3G Graphics Inc., Archive Arts, Cartesia Software, Image Club Graphics Inc., One Mile Up Inc., TechPool Studios, Totem Graphics Inc.). Students and instructors who use Data Structures and Other Objects Using C++ are welcome to use this presentation however they see fit, so long as this copyright notice remains intact. THE END
CSC212. Data Structure. Lecture 4 Container Classes. Instructor: George Wolberg Department of Computer Science City College of New York
CSC212 Data Structure Lecture 4 Container Classes Instructor: George Wolberg Department of Computer Science City College of New York 1 Outline Bag class definition/implementation details Inline functions
More informationLectures 4 & 5 Container Classes
CSC212 Data Structure - Section FG Lectures 4 & 5 Container Classes Instructor: Feng HU Department of Computer Science City College of New York 1 Container Classes A container class is a data type that
More informationLinked Lists in Action
Linked Lists in Action Chapter 5 introduces the oftenused data structure of linked lists. This presentation shows how to implement the most common operations on linked lists. CHAPTER 5 Data Structures
More informationHeaps. A heap is a certain kind of complete binary tree.
Heaps Heaps A heap is a certain kind of complete binary tree. Heaps Root A heap is a certain kind of complete binary tree. When a complete binary tree is built, its first node must be the root. Heaps Complete
More informationPreconditions and Postconditions. What are Preconditions and Postconditions? Example. Example
Preconditions and Postconditions 1 Preconditions and Postconditions 2 Data Structures and Other Objects Using C++ An important topic: preconditions and postconditions. They are a method of specifying what
More informationComplete Binary Trees
Complete Binary Trees Chapter 10 introduces trees. This presentation illustrates the simplest kind of trees: Complete Binary Trees. Data Structures and Other Objects Using C++ Binary Trees A binary tree
More informationLecture 9 Linked Lists
CSC212 Data Structure - Section FG Lecture 9 Linked Lists Instructor: Feng HU Department of Computer Science City College of New York Motivation In a sequence using an array, inserting a new item needs
More informationPointers and Dynamic Arrays
Pointers and Dynamic Arrays Pointers A pointer is the memory address of a variable Memory addresses can be used as names for variables If a variable is stored in three memory locations, the address of
More informationLecture 18 Heaps and Priority Queues
CSC212 Data Structure - Section FG Lecture 18 Heaps and Priority Queues Instructor: Feng HU Department of Computer Science City College of New York Heaps Chapter 11 has several programming projects, including
More informationCSC212 Data Structure - Section FG
CSC212 Data Structure - Section FG Lecture 21 Quadratic Sorting Instructor: Feng HU Department of Computer Science City College of New York Quadratic Sorting Data Structures and Other Objects Using C++
More informationRecursive Thinking. A Car Object. A Car Object. A Car Object. To start the example, think about your favorite family car
Recursive Thinking 1 2 Data Structures and Other Objects Using C++ Chapter 9 introduces the technique of recursive programming. As you have seen, recursive programming involves spotting smaller occurrences
More informationCSC212. Data Structure. Lecture 9 Templates, Iterators and STL. Instructor: George Wolberg Department of Computer Science City College of New York
CSC212 Data Structure Lecture 9 Templates, Iterators and STL Instructor: George Wolberg Department of Computer Science City College of New York Topics Template Functions and Template Classes for code that
More informationPreconditions and Postconditions
1 Preconditions and Postconditions An important topic: preconditions and postconditions. They are a method of specifying what a function accomplishes. Data Structures and Other Objects Using C++ This is
More informationHeaps. Data Structures and Other Objects Using C++
Heaps 1 Chapter 11 has several programming projects, including a project that uses heaps. This presentation shows you what a heap is, and demonstrates two of the important heap algorithms. Data Structures
More informationTemplate Functions. CHAPTER 6 Data Structures and Other Objects
Template Functions CHAPTER 6 Data Structures and Other Objects Chapter 6 introduces templates, which are a C++ feature that easily permits the reuse of existing code for new purposes. This presentation
More informationObject Oriented Programming
Object Oriented Programming 1 Data Structures and Other Objects Using C++ Chapter 2 introduces Object Oriented Programming. OOP is a relatively new approach to programming which supports the creation of
More informationCan you think of a situation where this would occur?
Preconditions and Postconditions An important topic: preconditions and postconditions. They are one way of specifying what a method accomplishes. Data Structures and Other Objects Using Java Preconditions
More informationChapter 12 discusses several ways of storing information in an array, and later searching for the. Hash tables are a common
CSC212 Data Structure t Lecture 20 Hashing Instructor: George Wolberg Department of Computer Science City College of New York Hash Tables Data Structures and Other Objects Using C++ Chapter 12 discusses
More informationCSC212. Data Structure. Lecture 13 Trees and Tree Traversals. Instructor: Prof. George Wolberg Department of Computer Science City College of New York
CSC212 Data Structure Lecture 13 Trees and Tree Traversals Instructor: Prof. George Wolberg Department of Computer Science City College of New York Motivation Linear structures arrays dynamic arrays linked
More informationReview for Test 1 (Chapter 1-5)
Review for Test 1 (Chapter 1-5) 1. Software development 1. Pre-conditions and Post-conditions 2. Running time analysis Big O Timing loops and nested loops 1) Write the simplest big-o expression to describe
More informationCSC212 Data Structure - Section FG
CSC212 Data Structure - Section FG Lecture 17 B-Trees and the Set Class Instructor: Feng HU Department of Computer Science City College of New York @ Feng HU, 2016 1 Topics Why B-Tree The problem of an
More informationLAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS
LAB 5, THE HIDDEN DELIGHTS OF LINKED LISTS Questions are based on the Main and Savitch review questions for chapter 5 in the Exam Preparation section of the webct course page. In case you haven t observed
More informationCSCI-1200 Data Structures Fall 2017 Lecture 10 Vector Iterators & Linked Lists
CSCI-1200 Data Structures Fall 2017 Lecture 10 Vector Iterators & Linked Lists Review from Lecture 9 Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately,
More informationPRACTICE MIDTERM EXAM #2
This practice exam is based on the actual midterm exam from Cynthia s Spring 2014 class. It did not include a classes problem (which you should expect this quarter), and the memory/pointers problem covered
More information1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking
Review for Test 2 (Chapter 6-10) Chapter 6: Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B.
More informationSets and MultiSets. Contents. Steven J. Zeil. July 19, Overview of Sets and Maps 4
Steven J. Zeil July 19, 2013 Contents 1 Overview of Sets and Maps 4 1 2 The Set ADT 6 2.1 The template header................................. 14 2.2 Internal type names.................................
More informationa data type is Types
Pointers Class 2 a data type is Types Types a data type is a set of values a set of operations defined on those values in C++ (and most languages) there are two flavors of types primitive or fundamental
More informationCSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)
CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) HW6 NOTE: Do not use the STL map or STL pair for HW6. (It s okay to use them for the contest.)
More informationData Structures. Lecture 1: Introduction CSC212. Instructor: George Wolberg Department of Computer Science City College of New York
CSC212 Data Structures Lecture 1: Introduction Instructor: George Wolberg Department of Computer Science City College of New York George Wolberg, 2016 1 Outline of this lecture Course Objectives and Schedule
More informationLargest Online Community of VU Students
WWW.VUPages.com WWW.VUTUBE.EDU.PK http://forum.vupages.com Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions
More informationIntermediate Programming & Design (C++) Classes in C++
Classes in C++ A class is a data type similar to a C structure. It includes various local data (called data members) together with constructors, destructors and member functions. All of them are called
More informationCOEN244: Class & function templates
COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library
More informationLargest Online Community of VU Students
WWW.VUPages.com WWW.VUTUBE.EDU.PK http://forum.vupages.com Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions
More information1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?
Review for Final (Chapter 6 13, 15) 6. Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B. To
More informationCSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists
Review from Lecture 8 CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators,
More informationCSCI-1200 Computer Science II Spring 2006 Test 3 Practice Problem Solutions
CSCI-1200 Computer Science II Spring 2006 Test 3 Practice Problem Solutions 1. You are given a map that associates strings with lists of strings. The definition is: map words; Write
More informationPointers & Dynamic Arrays
Pointers & Dynamic Arrays Allocating memory at run-time pointers 1 Review of pointers Pointer: variable that holds the address of a memory location as its value Pointers are used to indirectly reference
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationCSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators
CSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators Review from Lecture 7 Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators, and destructors
More informationCSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists
Review from Lecture 8 CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately, erasing items
More informationCSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators
Review from Lecture 7 CSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators, and destructors
More informationC++ Programming Fundamentals
C++ Programming Fundamentals 205 Elvis C. Foster Lecture 08: Working with Vectors In lectures 5 and 6, it was established that C++ allows you to create and manage a dynamic list by declaring the list as
More informationProgramming with Haiku
Programming with Haiku Lesson 2 Written by DarkWyrm All material 2010 DarkWyrm In our first lesson, we learned about how to generalize type handling using templates and some of the incredibly flexible
More informationObject-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering
Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 11 Winter 2011/12 Jan 10 Automatic Variables All variables so far have been defined inside a
More informationProgramming in C/C Lecture 2
Programming in C/C++ 2005-2006 Lecture 2 http://few.vu.nl/~nsilvis/c++/2006 Natalia Silvis-Cividjian e-mail: nsilvis@few.vu.nl vrije Universiteit amsterdam News Check announcements on the C/C++ website
More informationEXAM Computer Science 1 Part 1
Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari
More informationCSCI-1200 Data Structures Spring 2018 Lecture 16 Trees, Part I
CSCI-1200 Data Structures Spring 2018 Lecture 16 Trees, Part I Review from Lecture 15 Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.
More informationPointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017
Pointer Arithmetic Lecture 4 Chapter 10 Robb T. Koether Hampden-Sydney College Wed, Jan 25, 2017 Robb T. Koether (Hampden-Sydney College) Pointer Arithmetic Wed, Jan 25, 2017 1 / 36 1 Pointer Arithmetic
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationLectures 6/7 Pointers and Dynamic Arrays
CSC212 Data Structure - Section FG Lectures 6/7 Pointers and Dynamic Arrays Instructor: Feng HU Department of Computer Science City College of New York @ Feng HU, 2016 1 Why Pointers and Dynamic Memory
More informationCSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists
CSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists Review from Lecture 9 Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately,
More information11. Generic Programming and Design Patterns. 8. Juli 2011
8. Juli 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 26 Outline Recapitulation Template Programming An Overview over the STL Design Patterns (skipped) Evaluation/feedback
More informationArrays. Week 4. Assylbek Jumagaliyev
Arrays Week 4 Assylbek Jumagaliyev a.jumagaliyev@iitu.kz Introduction Arrays Structures of related data items Static entity (same size throughout program) A few types Pointer-based arrays (C-like) Arrays
More informationData Structures - Section FG
CSC212 Data Structures - Section FG Lecture 1: Introduction Instructor: Feng HU fhu@gradcenter.cuny.edu Department of Computer Science City College of New York Feng HU, 2016 1 Outline of this lecture Course
More informationCSCI-1200 Data Structures Fall 2017 Lecture 17 Trees, Part I
Review from Lecture 16 CSCI-1200 Data Structures Fall 2017 Lecture 17 Trees, Part I Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.
More informationObject-Oriented Programming for Scientific Computing
Object-Oriented Programming for Scientific Computing Traits and Policies Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 11. Juli 2017
More informationCSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic
CSCI-1200 Data Structures Spring 2014 Lecture 5 Pointers, Arrays, Pointer Arithmetic Announcements: Test 1 Information Test 1 will be held Monday, February 10th, 2014 from 6-7:50pm, Lab sections 1-5 and
More informationArray Elements as Function Parameters
Arrays Class 26 Array Elements as Function Parameters we have seen that array elements are simple variables they can be used anywhere a normal variable can unsigned values [] {10, 15, 20}; unsigned quotient;
More informationCh 4 Pointers and Dynamic Arrays
Ch 4 Pointers and Dynamic Arrays Pointers and Dynamic Memory Pointers and Arrays as Parameters The Bag Class with a Dynamic Array Prescription for a Dynamic Class Programming Project: The String Class
More informationContainer Class and Integrators, Proxy Class EC6301-OOPS AND DATA STRUCTURES
Container Class and Integrators, Proxy Class Container Class A container class is a data type that is capable of holding a collection of items. A container stores many entities and provide sequential or
More informationpointers + memory double x; string a; int x; main overhead int y; main overhead
pointers + memory computer have memory to store data. every program gets a piece of it to use as we create and use more variables, more space is allocated to a program memory int x; double x; string a;
More informationBasic Array Implementation Exception Safety
Basic Array Implementation Exception Safety CS 311 Data Structures and Algorithms Lecture Slides Monday, October 26, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks
More informationIntroducing C++ to Java Programmers
Introducing C++ to Java Programmers by Kip Irvine updated 2/27/2003 1 Philosophy of C++ Bjarne Stroustrup invented C++ in the early 1980's at Bell Laboratories First called "C with classes" Design Goals:
More informationBinary Search Trees Part Two
Binary Search Trees Part Two Recap from Last Time Binary Search Trees A binary search tree (or BST) is a data structure often used to implement maps and sets. The tree consists of a number of nodes, each
More informationLargest Online Community of VU Students
WWW.VUPages.com http://forum.vupages.com WWW.VUTUBE.EDU.PK Largest Online Community of VU Students MIDTERM EXAMINATION SEMESTER FALL 2003 CS301-DATA STRUCTURE Total Marks:86 Duration: 60min Instructions
More informationCSCI-1200 Data Structures Spring 2015 Lecture 18 Trees, Part I
CSCI-1200 Data Structures Spring 2015 Lecture 18 Trees, Part I Review from Lectures 17 Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 3 Monday, April 17, 2017 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 3 Monday, April 17, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,
More informationIV. Stacks. A. Introduction 1. Consider the 4 problems on pp (1) Model the discard pile in a card game. (2) Model a railroad switching yard
IV. Stacks 1 A. Introduction 1. Consider the problems on pp. 170-1 (1) Model the discard pile in a card game (2) Model a railroad switching yard (3) Parentheses checker () Calculate and display base-two
More information1. Which of the following best describes the situation after Line 1 has been executed?
Instructions: Submit your answers to these questions to the Curator as OQ3 by the posted due date and time. No late submissions will be accepted. For the next three questions, consider the following short
More informationArrays. Returning arrays Pointers Dynamic arrays Smart pointers Vectors
Arrays Returning arrays Pointers Dynamic arrays Smart pointers Vectors To declare an array specify the type, its name, and its size in []s int arr1[10]; //or int arr2[] = {1,2,3,4,5,6,7,8}; arr2 has 8
More informationTrees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.
Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters
More informationChapter 17: Linked Lists
Chapter 17: Linked Lists Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 17.1 Introduction to the
More informationCSE 100: C++ TEMPLATES AND ITERATORS
CSE 100: C++ TEMPLATES AND ITERATORS Announcements Gradesource and clickers: We ll be making one more pass for unregistered clickers tonight, but after that you ll be on your own How is Assignment 1 going?
More informationThe American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011
The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS
More informationCSE 100: C++ TEMPLATES AND ITERATORS
1 CSE 100: C++ TEMPLATES AND ITERATORS 2 Announcements Look out for the extra weekend section More on git and C++ (iterators) Live demo by your friendly tutors Not mandatory but it will be fun Bring your
More informationSTL: C++ Standard Library
STL: C++ Standard Library Encapsulates complex data structures and algorithms CSC 330 OO Software Design 1 We ve emphasized the importance of software reuse. Recognizing that many data structures and algorithms
More informationComposition I. composition is a way to combine or compose multiple classes together to create new class
Composition I composition is a way to combine or compose multiple classes together to create new class composition has-a relationship a car has-a gear-box a graduate student has-a course list if XX has-a
More informationCPSC 427a: Object-Oriented Programming
CPSC 427a: Object-Oriented Programming Michael J. Fischer Lecture 17 November 1, 2011 CPSC 427a, Lecture 17 1/21 CPSC 427a, Lecture 17 2/21 CPSC 427a, Lecture 17 3/21 A bit of history C++ standardization.
More information6. Pointers, Structs, and Arrays. March 14 & 15, 2011
March 14 & 15, 2011 Einführung in die Programmierung Introduction to C/C++, Tobias Weinzierl page 1 of 47 Outline Recapitulation Pointers Dynamic Memory Allocation Structs Arrays Bubble Sort Strings Einführung
More informationThis examination has 11 pages. Check that you have a complete paper.
MARKING KEY The University of British Columbia MARKING KEY Computer Science 252 2nd Midterm Exam 6:30 PM, Monday, November 8, 2004 Instructors: K. Booth & N. Hutchinson Time: 90 minutes Total marks: 90
More informationSolution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Summer I Instructions:
VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted
More informationLecture Notes on Memory Layout
Lecture Notes on Memory Layout 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 11 1 Introduction In order to understand how programs work, we can consider the functions,
More informationCSCI-1200 Data Structures Fall 2012 Lecture 5 Pointers, Arrays, Pointer Arithmetic
CSCI-1200 Data Structures Fall 2012 Lecture 5 Pointers, Arrays, Pointer Arithmetic Announcements: Test 1 Information Test 1 will be held Tuesday, September 18th, 2012 from 2-3:50pm in West Hall Auditorium.
More informationData Structures and Algorithms
Data Structures and Algorithms Alice E. Fischer Lecture 3 217 Alice E. Fischer Data Structures L3... 1/31 1 Arrays Growing Arrays vectors 2 3 Empty Lists Inserting Data - Unsorted Inserting Data - Sorted
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationAbstract Data Types (ADT) and C++ Classes
Abstract Data Types (ADT) and C++ Classes 1-15-2013 Abstract Data Types (ADT) & UML C++ Class definition & implementation constructors, accessors & modifiers overloading operators friend functions HW#1
More informationPurpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures
C++ Review 1 Purpose of Review Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures 2 Class The Class defines the data structure
More information1 Deletion in singly linked lists (cont d) 1 Other Functions. 1 Doubly Linked Lists. 1 Circular lists. 1 Linked lists vs. arrays
Unit 3: Linked Lists Part 2: More on Linked Lists 1 Deletion in singly linked lists (cont d) 1 Other Functions Engineering 4892: Data Structures 1 Doubly Linked Lists Faculty of Engineering & Applied Science
More informationC++ Programming Fundamentals
C++ Programming Fundamentals 269 Elvis C. Foster Lecture 11: Templates One of the contemporary sophistries of C++ programming is defining and manipulating templates. This lecture focuses on this topic.
More informationCSC212 Data Structure - Section FG
CSC212 Data Structure - Section FG Lecture 10 The Bag and Sequence Classes with Linked Lists Instructor: Feng HU Department of Computer Science City College of New York @ Feng HU, 2016 1 Reviews: Node
More informationExercise 6.2 A generic container class
Exercise 6.2 A generic container class The goal of this exercise is to write a class Array that mimics the behavior of a C++ array, but provides more intelligent memory management a) Start with the input
More informationC++ 11 and the Standard Library: Containers, Iterators, Algorithms
and the Standard Library:,, Comp Sci 1575 Outline 1 2 3 4 Outline 1 2 3 4 #i n clude i n t main ( ) { i n t v a l u e 0 = 5 ; // C++ 98 i n t v a l u e 1 ( 5 ) ; // C++ 98 i n t v a
More informationl Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationPointers. 1 Background. 1.1 Variables and Memory. 1.2 Motivating Pointers Massachusetts Institute of Technology
Introduction to C++ Massachusetts Institute of Technology ocw.mit.edu 6.096 Pointers 1 Background 1.1 Variables and Memory When you declare a variable, the computer associates the variable name with a
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationC++ Final Exam 2017/2018
1) All of the following are examples of integral data types EXCEPT. o A Double o B Char o C Short o D Int 2) After the execution of the following code, what will be the value of numb if the input value
More information21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;
- 147 - Advanced Concepts: 21. Exceptions Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.
More informationLecture 4. 1 Statements: 2 Getting Started with C++: LESSON FOUR
1 Statements: A statement in a computer carries out some action. There are three types of statements used in C++; they are expression statement, compound statement and control statement. Expression statement
More informationdouble d0, d1, d2, d3; double * dp = new double[4]; double da[4];
All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers
More information