Linked Lists in Action
|
|
- Garey Wilkerson
- 5 years ago
- Views:
Transcription
1 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 and Other Objects
2 Declarations for Linked Lists For this presentation, nodes in a linked list are objects, as shown here. class node { public: typedef double value_type;... private value_type data_field; node *link_field; }; 10 data_field link_field 15 7 data_field link_field data_field link_field
3 Declarations for Linked Lists The data_field of each node is a type called value_type, defined by a typedef. class node { public: typedef int value_type;... private value_type data_field; node *link_field; }; 10 data_field link_field 15 7 data_field link_field data_field link_field
4 Declarations for Linked Lists Each node also contains a link_field which is a pointer to another node. class node { public: typedef int value_type;... private value_type data_field; node *link_field; }; 10 data_field link_field 15 7 data_field link_field data_field link_field
5 Declarations for Linked Lists A program can keep track of the front node by using a pointer variable such as in this example. Notice that is not a node -- it is a pointer to a node. 10 data_field 15 data_field link_field link_field 7 data_field link_field
6 Declarations for Linked Lists A program can keep track of the front node by using a pointer variable such as. Notice that is not a node -- it is a pointer to a node. We represent the empty list by storing in the head pointer.
7 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); We want to add a new entry,, to the front of the linked list shown here entry 7
8 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); Create a new node, pointed to by a local variable insert_ptr. insert_ptr entry 7
9 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node; insert_ptr entry 7
10 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node; Place the data in the new node's data_field. insert_ptr entry 7
11 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node; Place the data in the new node's data_field. Connect the new node to the front of the list. 10 insert_ptr 15 entry 7
12 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node(entry, ); The correct new node can be completely created in one step by calling an appropriate node constructor. entry 10 insert_ptr 15 7
13 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node(entry, ); Make the old head pointer point to the new node. insert_ptr entry 7
14 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node(entry, ); = insert_ptr; insert_ptr entry 7
15 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry); insert_ptr = new node(entry, ); = insert_ptr; When the function returns, the linked list has a new node at the front
16 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr;
17 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr; Does the function work correctly for the empty list?
18 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr; Does the function work correctly for the empty list? entry
19 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr; entry insert_ptr
20 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr; insert_ptr entry
21 Inserting a Node at the Front void list_head_insert(node*&, const node::value_type& entry) { node *insert_ptr; } insert_ptr = new node(entry, ); = insert_ptr; When the function returns, the linked list has one node.
22 Caution! Always make sure that your linked list functions work correctly with an empty list. EMPTY LIST
23 Pseudocode for Inserting Nodes Nodes are often inserted at places other than the front of a linked list. There is a general pseudocode that you can follow for any insertion function...
24 Pseudocode for Inserting Nodes Determine whether the new node will be the first node in the linked list. If so, then there is only one step: list_head_insert(, entry);
25 Pseudocode for Inserting Nodes Determine whether the new node will be the first node in the linked list. If so, then there is only one step: list_head_insert(, entry);
26 Pseudocode for Inserting Nodes Determine whether the new node will be the first node in the linked list. If so, then there is only one step: list_head_insert(, entry); A pointer to the head of the list
27 Pseudocode for Inserting Nodes Determine whether the new node will be the first node in the linked list. If so, then there is only one step: list_head_insert(, entry);
28 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position.
29 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position. In this example, the new node will be the second node previous_ptr
30 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position Look at the pointer which is in the node *previous_ptr previous_ptr What is the name of this orange pointer? 7
31 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position This pointer is called previous_ptr->link_field (although this name may be private to the node) previous_ptr What is the name of this orange pointer? 7
32 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position previous_ptr->link_field points to the head of a small linked list, with 10 and 7 previous_ptr
33 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position. The new node must be inserted at the front of this small linked list. previous_ptr Write one C++ statement which will do the insertion. 7
34 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position. list_head_insert(previous_ptr->link_field, entry); previous_ptr What might cause this statement to fail to compile? 7
35 Pseudocode for Inserting Nodes Otherwise (if the new node will not be first): Start by setting a pointer named previous_ptr to point to the node which is just before the new node's position. list_head_insert(previous_ptr->link( ), entry); previous_ptr Use a node member function to get the link field if needed. 7
36 Pseudocode for Inserting Nodes Determine whether the new node will be the first node in the linked list. If so, then there is only one step: list_head_insert(, entry); Otherwise (if the new node will not be first): Set a pointer named previous_ptr to point to the node which is just before the new node's position. Make the function call: list_head_insert(previous_ptr->link( ), entry);
37 Pseudocode for Inserting Nodes The process of adding a new node in the middle of a list can also be incorporated as a separate function. This function is called list_insert in the linked list toolkit of Section 5.2.
38 Pseudocode for Removing Nodes Nodes often need to be removed from a linked list. As with insertion, there is a technique for removing a node from the front of a list, and a technique for removing a node from elsewhere. We ll look at the pseudocode for removing a node from the front of a linked list.
39 Removing the Head Node Start by setting up a temporary pointer named remove_ptr to the head node. remove_ptr
40 Removing the Head Node Set up remove_ptr. = remove_ptr->link( ); Draw the change that this statement will make to the linked list. remove_ptr
41 Removing the Head Node Set up remove_ptr. = remove_ptr->link( ); remove_ptr
42 Removing the Head Node Set up remove_ptr. = remove_ptr->link( ); delete remove_ptr; // Return the node's memory to heap. remove_ptr
43 Removing the Head Node Here s what the linked list looks like after the removal finishes
44 Summary It is easy to insert a node at the front of a list. The linked list toolkit also provides a function for inserting a new node elsewhere It is easy to remove a node at the front of a list. The linked list toolkit also provides a function for removing a node elsewhere--you should read about this function and the other functions of the toolkit.
45 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
Lecture 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 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 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 informationTypes of Containers: Sequences
Types of Containers: Sequences 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
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 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 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 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 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 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 informationCSC212. 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 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 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 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 informationLecture 19. Wednesday, February 23 CS 215 Fundamentals of Programming II - Lecture 19 1
Lecture 19 Log into Linux. Copy files on csserver from /home/hwang/cs215/lecture19/*.* Reminder: Homework 8 due today. Homework 9 is posted (PDF only). They are sample written midterm exam problems. It
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 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 informationvoid set_data(const value_type& new_data) { data_field = new_data; } void set_link(node* new_link) { link_field = new_link; }
node1.h Page 1 of 1 class node // TYPEDEF typedef double value_type; // CONSTRUCTOR node( const value_type& init_data = value_type( ), node* init_link = NULL ) data_field = init_data; link_field = init_link;
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 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 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 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 informationCpSc212 Goddard Notes Chapter 10. Linked Lists
CpSc212 Goddard Notes Chapter 10 Linked Lists 10.1 Links and Pointers The linked list is not an ADT in its own right; rather it is a way of implementing many data structures. It is designed to replace
More informationLinked Lists. It s a conspiracy!
Linked Lists It s a conspiracy! 1 Linked list: a data structure used to represent an ordered list Consists of a sequence of nodes A node consists of a data item and a reference to the next node -- the
More information(7 2) Classes: A Deeper Look D & D Chapter 9. Instructor - Andrew S. O Fallon CptS 122 (February 22, 2019) Washington State University
(7 2) Classes: A Deeper Look D & D Chapter 9 Instructor - Andrew S. O Fallon CptS 122 (February 22, 2019) Washington State University Key Concepts Composition relationship const objects const member functions
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 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 informationLab 2: ADT Design & Implementation
Lab 2: ADT Design & Implementation By Dr. Yingwu Zhu, Seattle University 1. Goals In this lab, you are required to use a dynamic array to design and implement an ADT SortedList that maintains a sorted
More informationCSE 333 Midterm Exam 5/9/14 Sample Solution
Question 1. (20 points) C programming. Implement the C library function strncpy. The specification of srncpy is as follows: Copy characters (bytes) from src to dst until either a '\0' character is found
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members
More informationTell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation }
template class StrVector { Tell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation } template class
More informationChapter 11. Abstract Data Types and Encapsulation Concepts
Chapter 11 Abstract Data Types and Encapsulation Concepts The Concept of Abstraction An abstraction is a view or representation of an entity that includes only the most significant attributes The concept
More informationTell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation }
template class StrVector { Tell compiler ValueType is a generic type. public: void push_back(const ValueType& elem); // rest of implementation } template class
More information11 'e' 'x' 'e' 'm' 'p' 'l' 'i' 'f' 'i' 'e' 'd' bool equal(const unsigned char pstr[], const char *cstr) {
This document contains the questions and solutions to the CS107 midterm given in Spring 2016 by instructors Julie Zelenski and Michael Chang. This was an 80-minute exam. Midterm questions Problem 1: C-strings
More informationUsing Semaphores CS 241. March 14, University of Illinois
Using Semaphores CS 241 March 14, 2012 University of Illinois Slides adapted in part from material accompanying Bryant & O Hallaron, Computer Systems: A Programmer's Perspective, 2/E 1 Announcements MP6
More informationNAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)
NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14) Some Material for your reference: Consider following C++ program. // A program
More informationLecture 6 Dynamic Classes and the Law of the Big Three. Instructor: George Wolberg Department of Computer Science City College of New York
CSC212 Data Structure Lecture 6 Dynamic Classes and the Law of the Big Three Instructor: George Wolberg Department of Computer Science City College of New York @ George Wolberg, 2016 1 Why Dynamic Classes
More informationSemantics of C++ Hauptseminar im Wintersemester 2009/10 Templates
Semantics of C++ Hauptseminar im Wintersemester 2009/10 Templates Sebastian Wild Technische Universität München 11.01.2010 Abstract In this work we will discuss about templates in C++, especially their
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 informationCS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes
CS111: PROGRAMMING LANGUAGE II Lecture 1: Introduction to classes Lecture Contents 2 What is a class? Encapsulation Class basics: Data Methods Objects Defining and using a class In Java 3 Java is an object-oriented
More informationPIC 10B Lecture 1 Winter 2014 Homework Assignment #3
PIC 10B Lecture 1 Winter 2014 Homework Assignment #3 Due Tuesday, February 4, 2014 by 5:00pm. Objectives: 1. To redefine the Big 3 : Copy constructor, Assignment operator, and Destructor for a class whose
More information2.1 Introduction UML Preliminaries Class diagrams Modelling delegation... 4
Department of Computer Science COS121 Lecture Notes Chapter 2- Memento design pattern Copyright c 2015 by Linda Marshall and Vreda Pieterse. All rights reserved. Contents 2.1 Introduction.................................
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 informationC++ - Lesson 2 This is a function prototype. a' is a function that takes an integer array argument and returns an integer pointer.
C++ - Lesson 2 1. Explain the following declarations: a) int *a(int a[]); This is a function prototype. 'a' is a function that takes an integer array argument and returns an integer pointer. b) const char
More informationPointers, Arrays and Parameters
Pointers, Arrays and Parameters This exercise is different from our usual exercises. You don t have so much a problem to solve by creating a program but rather some things to understand about the programming
More information(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University
(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University Key Concepts Function templates Defining classes with member functions The Rule
More informationDynamic memory in class Ch 9, 11.4, 13.1 & Appendix F
Dynamic memory in class Ch 9, 11.4, 13.1 & Appendix F Announcements Test next week (whole class) Covers: -Arrays -Functions -Recursion -Strings -File I/O Highlights - Destructors - Copy constructors -
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 information#06 More Structures LIFO FIFO. Contents. Queue vs. Stack 3. Stack Operations. Pop. Push. Stack Queue Hash table
Contents #06 More Structures -07 FUNDAMENTAL PROGRAMMING I Stack Queue Hash table DEPARTMENT OF COMPUTER ENGINEERING, PSU v. Queue vs. Stack Stack Operations IN IN OUT Push: add an item to the top Pop:
More informationConstants, References
CS 246: Software Abstraction and Specification Constants, References Readings: Eckel, Vol. 1 Ch. 8 Constants Ch. 11 References and the Copy Constructor U Waterloo CS246se (Spring 2011) p.1/14 Uses of const
More informationLECTURE 03 LINKED LIST
DATA STRUCTURES AND ALGORITHMS LECTURE 03 LINKED LIST IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD LINKED LISTS DEFINITION A linked list is a data structure where each object is stored in
More informationSuppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }
Multiple choice questions, 2 point each: 1. What output is produced by the following program? #include int f (int a, int &b) a = b + 1; b = 2 * b; return a + b; int main( ) int x=1, y=2, z=3;
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationby Pearson Education, Inc. All Rights Reserved. 2
Suppose you want to drive a car and make it go faster by pressing down on its accelerator pedal. Before you can drive a car, someone has to design it and build it. A car typically begins as engineering
More informationCSE 333 Midterm Exam 2/14/14
Name There are 4 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed
More informationCSE 143. Linked Lists. Linked Lists. Manipulating Nodes (1) Creating Nodes. Manipulating Nodes (3) Manipulating Nodes (2) CSE 143 1
CSE 143 Linked Lists [Chapter 4; Chapter 6, pp. 265-271] Linked Lists A linked list is a collection of dynamically allocated nodes Each node contains at least one member (field) that points to another
More informationA506 / C201 Computer Programming II Placement Exam Sample Questions. For each of the following, choose the most appropriate answer (2pts each).
A506 / C201 Computer Programming II Placement Exam Sample Questions For each of the following, choose the most appropriate answer (2pts each). 1. Which of the following functions is causing a temporary
More informationMemory Organization. The machine code and data associated with it are in the code segment
Memory Management Memory Organization During run time, variables can be stored in one of three pools : 1. Stack 2. Global area (Static heap) 3. Dynamic heap The machine code and data associated with it
More informationCpt S 122 Data Structures. Data Structures
Cpt S 122 Data Structures Data Structures Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Self Referential Structures Dynamic Memory Allocation
More information04-19 Discussion Notes
04-19 Discussion Notes PIC 10B Spring 2018 1 Constructors and Destructors 1.1 Copy Constructor The copy constructor should copy data. However, it s not this simple, and we need to make a distinction here
More informationObject-Oriented Principles and Practice / C++
Object-Oriented Principles and Practice / C++ Alice E. Fischer October 10, 2016 OOPP / C++ Lecture 7... 1/15 Construction and Destruction Kinds of Constructors Move Semantics OOPP / C++ Lecture 7... 2/15
More informationTechnical Note TN1026 Managing Groups and Users for Music Ace and Music Ace 2
1. Scope This technical note applies to all Music Ace and Music Ace 2 Educator versions, which include Single- Educator, Lab Pack and Network versions. For guidance managing groups and users for Music
More information(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University
(12-1) OOP: Polymorphism in C++ D & D Chapter 12 Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University Key Concepts Polymorphism virtual functions Virtual function tables
More informationArrays and Pointers in C & C++
Arrays and Pointers in C & C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++,
More informationChapter 10 Pointers and Dynamic Arrays. GEDB030 Computer Programming for Engineers Fall 2017 Euiseong Seo
Chapter 10 Pointers and Dynamic Arrays 1 Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic Classes, Pointers, Dynamic Arrays The this
More informationObject-Oriented Principles and Practice / C++
Object-Oriented Principles and Practice / C++ Alice E. Fischer May 13, 2013 OOPP / C++ Lecture 7... 1/27 Construction and Destruction Allocation and Deallocation Move Semantics Template Classes Example:
More informationCS250 Intro to CS II. Spring CS250 - Intro to CS II 1
CS250 Intro to CS II Spring 2017 CS250 - Intro to CS II 1 Topics Virtual Functions Pure Virtual Functions Abstract Classes Concrete Classes Binding Time, Static Binding, Dynamic Binding Overriding vs Redefining
More informationThis lecture presents ordered lists. An ordered list is one which is maintained in some predefined order, such as alphabetical or numerical order.
6.1 6.2 This lecture presents ordered lists. An ordered list is one which is maintained in some predefined order, such as alphabetical or numerical order. A list is numerically ordered if, for every item
More informationECE 2400 Computer Systems Programming, Fall 2017 Prelim 2 Prep
revision: 2017-11-04-22-45 These problems are not meant to be exactly like the problems that will be on the prelim. These problems are instead meant to represent the kind of understanding you should be
More informationAssertions, pre/postconditions
Programming as a contract Assertions, pre/postconditions Assertions: Section 4.2 in Savitch (p. 239) Specifying what each method does q Specify it in a comment before method's header Precondition q What
More informationC++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator
C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors
More informationProgramming 2. Object Oriented Programming. Daniel POP
Programming 2 Object Oriented Programming Daniel POP Week 5 Agenda 1. Modifiers: friend 2. Objects Wrap-up last week Self-reference Modifiers: static const mutable Object Oriented Programming Friends (I)
More informationImplementing Linked Lists
Implementing Linked Lists Lecture 16 Sections 17.1-17.3 Robb T. Koether Hampden-Sydney College Wed, Feb 27, 2013 Robb T. Koether (Hampden-Sydney College) Implementing Linked Lists Wed, Feb 27, 2013 1 /
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 informationWhat does it mean by information hiding? What are the advantages of it? {5 Marks}
SECTION ONE (COMPULSORY) Question #1 [30 Marks] a) Describe the main characteristics of object-oriented programming. {5 Marks Encapsulation the ability to define a new type and a set of operations on that
More informationEECS168 Exam 3 Review
EECS168 Exam 3 Review Exam 3 Time: 2pm-2:50pm Monday Nov 5 Closed book, closed notes. Calculators or other electronic devices are not permitted or required. If you are unable to attend an exam for any
More informationWriting an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and
Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()
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 informationLinked Lists. What Is A Linked List? Example Declarations. An Alternative Collections Data Structure. Head
Linked Lists An Alternative Collections Data Structure What Is A Linked List? A data structure using memory that expands and shrinks as needed Relies on identical nodes pointing or linked to other nodes
More informationCSCI Lab 9 Implementing and Using a Binary Search Tree (BST)
CSCI Lab 9 Implementing and Using a Binary Search Tree (BST) Preliminaries In this lab you will implement a binary search tree and use it in the WorkerManager program from Lab 3. Start by copying this
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationCS 225. Data Structures. Wade Fagen-Ulmschneider
CS 225 Data Structures Wade Fagen-Ulmschneider 5 6 7 8 9 10 11 int *x; int size = 3; x = new int[size]; for (int i = 0; i < size; i++) { x[i] = i + 3; delete[] x; heap-puzzle3.cpp Upcoming: Theory Exam
More informationDo not write in this area TOTAL. Maximum possible points: 75
Name: Student ID: Instructor: Borja Sotomayor Do not write in this area 1 2 3 4 5 6 7 TOTAL Maximum possible points: 75 This homework assignment is divided into two parts: one related to the fundamental
More informationCSE 333 Midterm Exam Cinco de Mayo, 2017 (May 5) Name UW ID#
Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,
More informationFinancial computing with C++
Financial Computing with C++, Lecture 6 - p1/24 Financial computing with C++ LG Gyurkó University of Oxford Michaelmas Term 2015 Financial Computing with C++, Lecture 6 - p2/24 Outline Linked lists Linked
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationNo Aids Allowed. Do not turn this page until you have received the signal to start. Read this entire page or you ll miss the bonus question.
CSC 148H Midterm Fall 2005 St. George Campus Duration 50 minutes Student Number: Family Name: Given Name: No Aids Allowed. Do not turn this page until you have received the signal to start. Read this entire
More informationCh. 11: References & the Copy-Constructor. - continued -
Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed
More informationChapter 10. Pointers and Dynamic Arrays. Copyright 2016 Pearson, Inc. All rights reserved.
Chapter 10 Pointers and Dynamic Arrays Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Pointers Pointer variables Memory management Dynamic Arrays Creating and using Pointer arithmetic
More informationCS 61B, Spring 1996 Midterm #1 Professor M. Clancy
CS 61B, Spring 1996 Midterm #1 Professor M. Clancy Problem 0 (1 point, 1 minute) Put your login name on each page. Also make sure you have provided the information requested on the first page. Problem
More informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
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 information(7-2) Operator Overloading D & D Chapter 10. Instructor - Andrew S. O Fallon CptS 122 (February 23, 2018) Washington State University
(7-2) Operator Overloading D & D Chapter 10 Instructor - Andrew S. O Fallon CptS 122 (February 23, 2018) Washington State University Key Concepts Keyword operator Operator overloading 2 What is Operator
More informationICOM 4035 Data Structures. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department
ICOM 4035 Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Readings Chapter 17 of textbook: Linked Lists ICOM 4035 Dr. Manuel Rodriguez Martinez 2 What is missing?
More informationIntroduction to Computing II (ITI 1121) Final Examination
Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of Engineering School of Electrical Engineering and Computer Science Introduction
More informationWELCOME TO CS 24! Problem Solving with Computers-II https://ucsb-cs24-s18.github.io/ Read the syllabus. Know what s required. Know how to get help. Enrollment status: 117/105 2 About me Diba Mirza (diba@ucsb.edu)
More informationC Introduction. Comparison w/ Java, Memory Model, and Pointers
CS 261 Fall 2018 Mike Lam, Professor C Introduction Comparison w/ Java, Memory Model, and Pointers Please go to socrative.com on your phone or laptop, choose student login and join room LAMJMU The C Language
More informationการทดลองท 8_2 Editor Buffer Array Implementation
การทดลองท 8_2 Editor Buffer Array Implementation * File: buffer.h * -------------- * This file defines the interface for the EditorBuffer class. #ifndef _buffer_h #define _buffer_h * Class: EditorBuffer
More informationObjective-C. Stanford CS193p Fall 2013
New language to learn! Strict superset of C Adds syntax for classes, methods, etc. A few things to think differently about (e.g. properties, dynamic binding) Most important concept to understand today:
More information