![Page 1: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/1.jpg)
Linked ListsPart One
![Page 2: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/2.jpg)
Outline for Today
● Linked Lists, Conceptually● A different way to represent a sequence.
● Linked Lists, In Code● Some cool new C++ tricks.
● Manipulating Lists Recursively● … is way easier than you’d expect!
● Manipulating Lists Iteratively● … is trickier than you’d expect!
![Page 3: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/3.jpg)
Changing Offices
![Page 4: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/4.jpg)
Dr. Cynthia Lee is no longer in room 100.
She can be found in room 108.
The Sign on Room 100
Room100
Room108
![Page 5: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/5.jpg)
Dr. Cynthia Lee is no longer in room 108.
She can be found in room 190.
The Sign on Room 108
Room100
Room108
Room190
![Page 6: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/6.jpg)
Dr. Cynthia Lee is no longer in room 190.
She can be found in room 192.
The Sign on Room 190
Room100
Room108
Room190
Room192
![Page 7: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/7.jpg)
The Sign on Room 192
Welcome to Cynthia’sOffice!
Room100
Room108
Room190
Room192
![Page 8: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/8.jpg)
Linked Lists at a Glance
1 2 3
● 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.● The end of the list is marked with some special
indicator.
![Page 9: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/9.jpg)
Linked Lists at a Glance
1 2 3
● 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.● The end of the list is marked with some special
indicator.
![Page 10: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/10.jpg)
Linked Lists at a Glance
1 2 3137
● 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.● The end of the list is marked with some special
indicator.
![Page 11: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/11.jpg)
Linked Lists at a Glance
1 3137
● 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.● The end of the list is marked with some special
indicator.
![Page 12: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/12.jpg)
...an empty list,or...
a single cell... ... that points at another linked list.
A Linked List is Either...
1 2 3137
![Page 13: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/13.jpg)
Representing Linked Lists
![Page 14: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/14.jpg)
...an empty list,or...
a single cell... ... that points at another linked list.
A Linked List is Either...
![Page 15: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/15.jpg)
...an empty list,or...
a single cell... ... that points at another linked list.
A Linked List is Either...
![Page 16: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/16.jpg)
a single cell... ... that points at another linked list.
A Linked List is Either...struct Cell { string value; Cell* next;};
Hi Mom!
![Page 17: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/17.jpg)
struct Cell { string value; Cell* next;};
Cell* list = new Cell;
list
We just want a single cell, not an array of cells. To get the space we need, we’ll just say new Cell.
We just want a single cell, not an array of cells. To get the space we need, we’ll just say new Cell.
Notice that list is still a Cell*, a pointer to a cell.
It still says “look over there for your Cell”
rather than “I’m a Cell!”
Notice that list is still a Cell*, a pointer to a cell.
It still says “look over there for your Cell”
rather than “I’m a Cell!”
Yes, it’s a bit confusing that C++ uses the same types to mean “look over there for an array of Cells” and “look over
there for a single Cell.”
Yes, it’s a bit confusing that C++ uses the same types to mean “look over there for an array of Cells” and “look over
there for a single Cell.”
![Page 18: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/18.jpg)
struct Cell { string value; Cell* next;};
Cell* list = new Cell;list->value = "dikdik!";
dikdik!
list
Because list is a pointer to a Cell, we use the arrow operator -> instead of the
dot operator.
Think of list->value as saying “start at list,
follow an arrow, then pick the value field.”
Because list is a pointer to a Cell, we use the arrow operator -> instead of the
dot operator.
Think of list->value as saying “start at list,
follow an arrow, then pick the value field.”
![Page 19: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/19.jpg)
struct Cell { string value; Cell* next;};
Cell* list = new Cell;list->value = "dikdik!";list->next = new Cell;list->next->value = "quokka!";list->next->next = new Cell;list->next->next->value = "pudu!";list->next->next->next = nullptr;
dikdik!
list
quokka! pudu!
![Page 20: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/20.jpg)
struct Cell { string value; Cell* next;};
Cell* list = new Cell;list->value = "dikdik!";list->next = new Cell;list->next->value = "quokka!";list->next->next = new Cell;list->next->next->value = "pudu!";list->next->next->next = nullptr;
dikdik!
list
quokka! pudu!
C++ uses the nullptr keyword to mean “a pointer
that doesn’t point at anything.”
(Older code uses NULL instead of nullptr; that’s also okay,
but we recommend nullptr.)
C++ uses the nullptr keyword to mean “a pointer
that doesn’t point at anything.”
(Older code uses NULL instead of nullptr; that’s also okay,
but we recommend nullptr.)
![Page 21: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/21.jpg)
...an empty list,represented bynullptr, or...
a single linked listcell that points...
... at another linked list.
A Linked List is Either...
![Page 22: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/22.jpg)
Time-Out for Announcements!
![Page 23: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/23.jpg)
![Page 24: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/24.jpg)
Assignment 5
● Assignment 4 was due at the start of class today.
● Assignment 5 (Data Sagas) goes out today. It’s due Wednesday, February 27th.● Play around with searching, sorting, big-O
notation, and class design!● Discover some cool patterns in real data sets!
● YEAH Hours are today at 3:30PM in room 380-380Y. Slides will be posted in case you can’t make it.
![Page 25: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/25.jpg)
Midterm Exam
● The midterm exam is next Tuesday, February 19 from 7:00PM – 10:00PM. Locations are divvied up by last (family) name:● A – K: Go to Bishop Auditorium● L – Z: Go to Hewlett 200
● It covers topics from Lectures 01 – 12 (up through and including big-O notation) and Assignments 0 – 4.
● The exam is closed-book and limited-note. You may bring one double-sided sheet of 8.5” × 11” of notes to the exam with you.
![Page 26: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/26.jpg)
Midterm Exam
● We will be administering the exam using a software tool called BlueBook.
● Visit the CS106B website, click the “BlueBook” link under the “Resources” tab, then download the BlueBook software.
● If you need a laptop for the exam and haven’t contacted us yet, please do so ASAP so we can plan accordingly.
![Page 27: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/27.jpg)
Practice Midterm Exam
● There’s a practice midterm exam up on the course website. It’s a minimally-modified version of the exam we gave out in Winter 2017.
● The password is
maplesyrup
and you’ll see why when you start the exam. 😃
![Page 28: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/28.jpg)
Back to CS106B!
![Page 29: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/29.jpg)
Printing a Linked List
![Page 30: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/30.jpg)
...an empty list,represented bynullptr, or...
a single linked listcell that points...
... at another linked list.
A Linked List is Either...
![Page 31: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/31.jpg)
...an empty list,represented bynullptr, or...
a single linked listcell that points...
... at another linked list.
A Linked List is Either...
dikdik! quokka! pudu!
![Page 32: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/32.jpg)
Linked Lists, Iteratively
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
1 2 43list
![Page 33: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/33.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 34: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/34.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 35: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/35.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 36: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/36.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 37: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/37.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 38: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/38.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 39: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/39.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 40: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/40.jpg)
Linked Lists, Iteratively
1 2 43
curr
● You can also navigate a linked list using a traditional for loop:for (Cell* curr = list; curr != nullptr; curr = curr->next) {
/* … do something with curr->value … */
}
list
![Page 41: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/41.jpg)
Building a Linked List(without hardcoding it)
![Page 42: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/42.jpg)
...an empty list,represented bynullptr, or...
a single linked listcell that points...
... at another linked list.
A Linked List is Either...
![Page 43: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/43.jpg)
Once More, With Iteration!
![Page 44: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/44.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
![Page 45: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/45.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
![Page 46: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/46.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
result
![Page 47: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/47.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
result
![Page 48: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/48.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
result
![Page 49: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/49.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
result
![Page 50: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/50.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
result
![Page 51: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/51.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
result
![Page 52: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/52.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
result
![Page 53: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/53.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
result
![Page 54: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/54.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell result
![Page 55: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/55.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
???
result
![Page 56: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/56.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
???
result
![Page 57: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/57.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
???
result
![Page 58: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/58.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
???
result
![Page 59: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/59.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
???
result
![Page 60: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/60.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
???
result
![Page 61: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/61.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
???
result
![Page 62: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/62.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
result
![Page 63: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/63.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
result
![Page 64: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/64.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
result
![Page 65: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/65.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
result
![Page 66: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/66.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!line
cell
dikdik!
result
![Page 67: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/67.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!
result
![Page 68: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/68.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!
result
![Page 69: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/69.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
dikdik!
result
![Page 70: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/70.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
dikdik!
result
![Page 71: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/71.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
dikdik!
result
![Page 72: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/72.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
dikdik!
result
![Page 73: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/73.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
???
dikdik!
result
![Page 74: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/74.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
???
dikdik!
result
![Page 75: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/75.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka!
???
dikdik!
result
![Page 76: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/76.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka!
???
dikdik!
result
![Page 77: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/77.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka! dikdik!
result
![Page 78: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/78.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka! dikdik!
result
![Page 79: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/79.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka! dikdik!
result
![Page 80: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/80.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka!line
cell
quokka! dikdik!
result
![Page 81: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/81.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka! dikdik!
result
![Page 82: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/82.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka! dikdik!
result
![Page 83: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/83.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka! dikdik!
result
![Page 84: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/84.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
result
![Page 85: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/85.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
result
![Page 86: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/86.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
result
![Page 87: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/87.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
???
![Page 88: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/88.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
???
![Page 89: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/89.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
???
![Page 90: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/90.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
???
![Page 91: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/91.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
![Page 92: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/92.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
![Page 93: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/93.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
![Page 94: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/94.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
resultcell
pudu!
![Page 95: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/95.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
pudu!
line
quokka! dikdik!
result
pudu!
![Page 96: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/96.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka! dikdik!
result
pudu!
It’s a bug: these elements are in the wrong order!
It’s a feature: we just implemented a stack using
linked lists!
It’s a bug: these elements are in the wrong order!
It’s a feature: we just implemented a stack using
linked lists!
![Page 97: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/97.jpg)
Cell* result = nullptr;while (true) {
string line = getLine("Next entry? ");if (line == "") break;
Cell* cell = new Cell;cell->value = line;
cell->next = result;result = cell;
}return result;
quokka! dikdik!
result
pudu!
It’s a bug: these elements are in the wrong order!
It’s a feature: we just implemented a stack using
linked lists!
It’s a bug: these elements are in the wrong order!
It’s a feature: we just implemented a stack using
linked lists!
![Page 98: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/98.jpg)
Your Action Items
● Read Chapter 11 of the Textbook● More on pointers, arrays, lists, etc.
● Download BlueBook● Gonna need that for the exam!
![Page 99: Linked Lists - Stanford University...Linked Lists at a Glance 1 2 3 A linked list is a data structure for storing a sequence of elements. Each element is stored separately from the](https://reader034.vdocuments.net/reader034/viewer/2022050212/5f5e83544b8d8e723e0c69e4/html5/thumbnails/99.jpg)
Next Time
● Pointers by Reference● Fun for the whole linked list family!
● Reimplementing Stacks and Queues● Worst-case efficiency, at a price!