This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved.

Slides:



Advertisements
Similar presentations
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
Advertisements

Chapter 17 vector and Free Store John Keyser’s Modifications of Slides By Bjarne Stroustrup
Review of Stacks and Queues Dr. Yingwu Zhu. Our Focus Only link-list based implementation of Stack class Won’t talk about different implementations of.
Chapter 6: Stacks STACK APPLICATIONS STACK IMPLEMENTATIONS CS
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Summary of lectures (1 to 11)
CS Data Structures Chapter 4 Lists.
Introduction to Classes and Objects CS-2303, C-Term Introduction to Classes and Objects CS-2303 System Programming Concepts (Slides include materials.
CS 1031 C++: Object-Oriented Programming Classes and Objects Template classes Operator Overloading Inheritance Polymorphism.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Pointer Data Type and Pointer Variables
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Memory Management CS Chakrabarti Variable storage thus far  Never used global variables  All variables allocated inside functions, passed.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
Copyright © 2012 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
Data Structures Week 5 Further Data Structures The story so far  We understand the notion of an abstract data type.  Saw some fundamental operations.
 2007 Pearson Education, Inc. All rights reserved C Data Structures.
Arrays and Linked Lists "All the kids who did great in high school writing pong games in BASIC for their Apple II would get to college, take CompSci 101,
Runtime Environments Compiler Construction Chapter 7.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
1 C - Memory Simple Types Arrays Pointers Pointer to Pointer Multi-dimensional Arrays Dynamic Memory Allocation.
Stack and Heap Memory Stack resident variables include:
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
Programming Languages by Ravi Sethi Chapter 6: Groupings of Data and Operations.
1 Data Structures - CSCI 102 CS102 C++ Pointers & Dynamic Objects Prof Tejada.
Pointers OVERVIEW.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
Pointers and Dynamic Memory Allocation Copyright Kip Irvine 2003, all rights reserved. Revised 10/28/2003.
1 CS 132 Spring 2008 Chapter 3 Pointers and Array-Based Lists read p
CS 106X Classes and Objects
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 4.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Lecture 10: 2/17/2003CS148 Spring CS148 Introduction to Programming II Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CNG 140 C Programming (Lecture set 12) Spring Chapter 13 Dynamic Data Structures.
Xiaoyan Li, CSC211 Data Structures Lecture 8 Dynamic Classes and the Law of the Big Three Instructor: Prof. Xiaoyan Li Department of Computer Science.
This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved.
This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved.
CS162 - Topic #6 Lecture: Pointers and Dynamic Memory –Review –Dynamically allocating structures –Combining the notion of classes and pointers –Destructors.
This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part R2. Elementary Data Structures.
Pointers and Linked Lists
Pointers and Linked Lists
Cinda Heeren / Geoffrey Tien
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Linked Lists Chapter 6 Section 6.4 – 6.6
Dr. Bernard Chen Ph.D. University of Central Arkansas
Programming Abstractions
Pass by Reference, const, readonly, struct
Programming Abstractions
ArrayLists 22-Feb-19.
Stacks and Queues.
Data Structures & Algorithms
Dynamic allocation (continued)
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All rights reserved. Based on slides created by Keith Schwarz, Julie Zelenski, Jerry Cain, Eric Roberts, Mehran Sahami, Stuart Reges, Cynthia Lee, and others. CS 106B Lecture 14 Feb 8, 2016 Chris Piech Linked Lists

2 恭禧发财

3 Midterm

4 Open Computer?

5 Conclusion: No open computers.

6 Midterm Questions?

7 Today’s Goals 1.Practice with dynamic allocation 2.Introduction to linked lists

8 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

9 How is the Stack Implemented?

10 Lets Write Vector

11 VectorInt class VectorInt { // in VectorInt.h public: VectorInt(); // constructor void add(int value); // append a value to the end int get(int index); // return the value at index private: type name; // member variables type name; // (data inside each object) };

12 Buggy VectorInt the First class VectorInt { // in VectorInt.h public: VectorInt(); // constructor void add(int value); // append a value to the end int get(int index); // return the value at index private: int value0; // member variables int value1; // (data inside each object) };

13 Problems with Stack Variables Variables have to be known at compile time. Not runtime.

14 Problems with Stack Variables Variables have to be known at compile time. Not runtime. Persistence is out of our control. Its hard to share a single large object between classes.

15 Dynamic Allocation!

16 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage.

17 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage.

18 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage

19 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage

20 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage

Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage image

22 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage image

23 Pointers GImage * image = new GImage(“cat.png”); // dynamically request memory for a new GImage. // calls the constructor. // store the address of the new GImage image

24 Pointers Example

25

26 Pointers int * intList = new int[n]; // dynamically request memory for n integers. // store the address of the provided ints. intList

27 Variables have to be known at compile time. Not runtime. Persistence is out of our control. Its hard to share a single large object between classes. How Does this Help?

28 Dig deeper

29 All Memory Has an Address RAM not disk Each program gets it’s own

30 URL Metaphore A pointer is like a URL. Not the actual page, the address of the page

31 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ?

32 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ?

33 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan 12634

34 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan

35 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan student 12634

36 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan student

37 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan student

38 Socrative Point * megan = new Point(); megan->setX(10); Point * student = megan; student->setY(7); cout getX(); cout << “ “; cout getY(); a) 10, 7 b) crashes c) ?, 7 d) ? ? x y megan 10 student 7

39

40 VectorInt class VectorInt { // in VectorInt.h public: VectorInt(); // constructor void add(int value); // append a value to the end int get(int index); // return the value at index private: type name; // member variables type name; // (data inside each object) };

41 Actual Vector class VectorInt { // in VectorInt.h public: VectorInt(); // constructor void add(int value); // append a value to the end int get(int index); // return the value at index private: int * data; };

42 Actual Vector class VectorInt { // in VectorInt.h public: VectorInt(); // constructor void add(int value); // append a value to the end int get(int index); // return the value at index private: int * data; int size; int allocatedSize; };

allocated length logical length element array Actual Vector

allocated length logical length element array 137 Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

allocated length logical length element array Actual Vector

68 Dynamic allocation was necessary

69 Benefits of Dynamic Allocation Can decide on the number of variables at run time. Control over variable lifespan Its easy to share a single large object.

70 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

71 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

72 Vector Big O?

73 Big O of Get? int VecInt::get(int index){ return data[index]; }

74 Big O of Get?

75 Big O of Get?

76 Add?

77 Big O of Add? void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; }

78 Big O of Add? void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; } Worst Case

79 Big O of Add? void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; } Worst Case

80 void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; } Big O of Add? Worst Case

81 void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; } Big O of Add? Worst Case

82 void VecInt::add(int v){ data[usedSize] = v; usedSize++; if(usedSize == allocatedSize) { doubleAllocation(); } void VecInt::doubleAllocation() { allocatedSize *= 2; int * newData = new int[allocatedSize]; for(int i = 0; i < usedSize; i++) { newData[i] = data[i]; } delete[] data; data = newData; } Big O of Add? Worst Case

83 Big O of Add?

84 Remove?

85 Big O of Remove? void VecInt::remove(int index){ for(int i = index; i < usedSize - 1; i++) { data[i] = data[i + 1]; } usedSize--; }

86 Big O of Remove?

87 Summary?

88 Vector Big O Get Add Remove

89 That’s fine.

90 How is the Stack Implemented?

91 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

92 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

93 VectorInt class StackInt { // in VectorInt.h public: StackInt (); // constructor void push(int value); // append a value to the end int pop(); // return the value at index private: VectorInt data; // member variables };

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

Excuse Me, Coming Through

104 Stack as Vector Big O Push Pop

105 There’s always a better way

106 What About This? int * data 9 8 push(7);

107 What About This? int * data push(7);

108 What About This? int * data push(7);

109 What About This? int * data push(7);

110 Oh Cool

111 What About This? int * data push(6);

112 What About This? int * data push(6); 6

113 What About This? int * data push(6); 6

114 What About This? int * data push(6); 6

115 What About This? int * data push(6); 6

116 And Pop?

117 What About This? int * data pop(); 6

118 What About This? int * data pop(); 6 int return 6

119 What About This? int * data pop(); 6 int return 6

120 What About This? int * data pop(); int return 6

121 What About This? int * data pop(); int return 6

122 Linked Lists!

123 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

124 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

125 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence. 123 Linked Lists

126 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence Linked Lists

127 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence Linked Lists

128 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence Linked Lists

129 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence Linked Lists

130 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the rest. The elements are then chained together into a sequence Linked Lists

131 Can efficiently splice new elements into the list or remove existing elements anywhere in the list. Never have to do a massive copy step; insertion is efficient in the worst-case. Has some tradeoffs; we'll see this later. Linked Lists

132 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Linked Lists

133 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Linked Lists

134 In C++, a structure is a type consisting of several individual variables all bundled together. To create a structure, we must Define what fields are in the structure, then Create a variable of the appropriate type. Similar to using classes – need to define and implement the class before we can use it. Structs

135 You can define a structure by using the struct keyword: struct TypeName { /* … field declarations … */ }; For those of you with a C background: in C++, “ typedef struct ” is not necessary. Structs

136 struct Tribute { string name; int districtNumber; }; Tribute t; t.name = "Katniss Everdeen"; t.districtNumber = 12; Structs

137 struct Tribute { string name; int districtNumber; }; Tribute t; t.name = "Katniss Everdeen"; t.districtNumber = 12; Structs

138 struct Tribute { string name; int districtNumber; }; Tribute t; t.name = "Katniss Everdeen"; t.districtNumber = 12; Structs

139 In C++, a class is a pair of an interface and an implementation. Interface controls how the class is to be used. Implementation specifies how it works. A struct is a stripped-down version of a class : Purely implementation, no interface. Primarily used to bundle information together when no interface is needed. Structs

140 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Structs

141 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Structs

142 We have seen the new keyword used to allocate arrays, but it can also be used to allocate single objects. The syntax: new T ( args ) creates a new object of type T passing the appropriate arguments to the constructor, then returns a pointer to it. Structs

143 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; Structs

144 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; Structs

145 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; t Structs

146 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Structs

147 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Structs

148 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Structs

149 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Structs

150 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Because t is a pointer to a Tribute, not an actual Tribute, we have to use the arrow operator to access the fields pointed at by t. Structs

151 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; ???? name districtNumbe r t Structs

152 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; Katniss Everdeen ???? name districtNumbe r t Structs

153 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; Katniss Everdeen ???? name districtNumbe r t Structs

154 struct Tribute { string name; int districtNumber; }; Tribute* t = new Tribute; t->name = "Katniss Everdeen"; t->districtNumber = 12; Katniss Everdeen 12 name districtNumbe r t Structs

155 As with dynamic arrays, you are responsible for cleaning up memory allocated with new. You can deallocate memory with the delete keyword: delete ptr; This destroys the object pointed at by the given pointer, not the pointer itself. ptr 137 Structs

156 As with dynamic arrays, you are responsible for cleaning up memory allocated with new. You can deallocate memory with the delete keyword: delete ptr; This destroys the object pointed at by the given pointer, not the pointer itself. ptr 137 Structs

157 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Building our Vocabulary

158 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Building our Vocabulary

159 When working with pointers, we sometimes wish to indicate that a pointer is not pointing to anything. In C++, you can set a pointer to NULL to indicate that it is not pointing to an object: ptr = NULL; This is not the default value for pointers; by default, pointers default to a garbage value. The Null Pointer

160 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Building our Vocabulary

161 In order to use linked lists, we will need to introduce or revisit several new language features: Structures Dynamic allocation Null pointers Building our Vocabulary

162 And now... linked lists!

163 A linked list is a chain of cells. Each cell contains two pieces of information: Some piece of data that is stored in the sequence, and A link to the next cell in the list. We can traverse the list by starting at the first cell and repeatedly following its link. Linked Lists

164 For simplicity, let's assume we're building a linked list of string s. We can represent a cell in the linked list as a structure: struct Cell { string value; /* ? */ next; }; The structure is defined recursively! Linked Lists

165 For simplicity, let's assume we're building a linked list of string s. We can represent a cell in the linked list as a structure: struct Cell { string value; Cell* next; }; The structure is defined recursively! Linked Lists

166 For simplicity, let's assume we're building a linked list of string s. We can represent a cell in the linked list as a structure: struct Cell { string value; Cell* next; }; The structure is defined recursively! Linked Lists

167 Building Linked Lists!

168 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

169 Vector Big O Monday Stack? Linked Lists Dynamic Allocation Today’s Goals River of Linked Lists

170 Today’s Goals 1.Practice with dynamic allocation 2.Introduction to linked lists