diff --git a/docs/compilation.html b/docs/compilation.html index dcdd4fc2f..261922cd1 100644 --- a/docs/compilation.html +++ b/docs/compilation.html @@ -22,7 +22,7 @@
#include
are not present, then it won't compile.#include "FileName.h"
and your file is named filename.h, this will NOT compile under Linux. Change your file name cases, or your #include
line.#include
lines? If it is complaining that it can't find exit()
, for example, be sure to #include <stdlib.h>
. Many compilers automatically include <stdlib.h>
and <stdio.h>
, which means you can directly call functions such as printf()
and exit()
without the appropriate #include
line. The compiler used by the submission system does not include, by default, any #include
files.#include
lines? If it is complaining that it can't find find()
, for example, be sure to #include <algorithm>
.using namespace std;
at the top of each file?make
(you learn about make and Makefiles about 1/3 of the way through the course), then your Makefile needs to be configured to properly compile the codeThis diagram shows a list containing two elements, the integers 3 and 7. Note that there are more methods in the List and ListItr classes than what is shown above. The head and tail pointers in the List class point to dummy nodes -- they are put there to make inserting elements into the list easier. It doesn't matter what the value of the dummy nodes is set to, as it won't be used. Each ListNode points to the nodes before and after it (although the dummy nodes each have one pointer pointing to NULL).
+This diagram shows a list containing two elements, the integers 3 and 7. Note that there are more methods in the List and ListItr classes than what is shown above. The head and tail pointers in the List class point to dummy nodes -- they are put there to make inserting elements into the list easier. It doesn't matter what the value of the dummy nodes is set to, as it won't be used. Each ListNode points to the nodes before and after it (although the dummy nodes each have one pointer pointing to nullptr).
Thus, our doubly linked list will have only one List object and many ListNode objects (2 more than the number of elements in the list). A ListItr is a separate object, which points to one element in the list (possibly a dummy node). As you call the various methods in ListItr to move the iterator forward and backward, the node that it points to will change.
A ListNode contains an integer value, as well as next and previous pointers to other ListNodes. View the ListNode.h (src) code for details.
@@ -90,7 +90,7 @@printList
When beginning to test your code, chances are your program will crash unexpectedly with a message similar to Segmentation fault (core dumped)
, commonly referred to as a segfault. Get prepared to see these often throughout the course, as unlike other programming languages like Java, C++ does not give any extra debugging information on a crash. In order to determine where and why your program is crashing, run your code through the debugger and look at the backtrace. Segfaults generally indicate that you are trying to dereference a NULL or invalid pointer, so those are good things to look out for.
When beginning to test your code, chances are your program will crash unexpectedly with a message similar to Segmentation fault (core dumped)
, commonly referred to as a segfault. Get prepared to see these often throughout the course, as unlike other programming languages like Java, C++ does not give any extra debugging information on a crash. In order to determine where and why your program is crashing, run your code through the debugger and look at the backtrace. Segfaults generally indicate that you are trying to dereference a nullptr or invalid pointer, so those are good things to look out for.
By the time the constructor finishes, we should have a functioning (but empty) list. This means that head
and tail
need to be set appropriately! What should they point to if the list is empty?
Make sure you are initializing the variables that are specified in the .h file and not declaring new variables that have the same name as those in the header file. Take a look back at lifecycle.cpp's constructors from Lab 1 if you need a refresher.
@@ -145,7 +145,7 @@makeEmpty
should clear the list of all elements (isEmpty
should return true after calling makeEmpty
). It should also make sure that head
and tail
no longer point to those deleted elements (what should they point to instead in an empty list?).
Since we have been dynamically allocating ListNodes, we must also be responsible for deleting them to ensure we do not leak memory. There are multiple ways to iterate through the list and delete
each ListNode -- experiment and see what makes the most sense to you.
-Important: once you delete a ListNode, you can no longer reliably access any of its data, such as its next
or previous
pointers! To make sure you don't do this accidentally, we recommend setting each ListNode to NULL as soon as you delete it.
next
or previous
pointers! To make sure you don't do this accidentally, we recommend setting each ListNode to nullptr as soon as you delete it.
The destructor should delete all dynamically-allocated memory, as we no longer need this List instance. Thus, it makes sense that we should delete all the elements we inserted (hint: do we already have a method for that?). However, what else do we dynamically allocate that we need to delete?
This one's interesting becaus it's a non-member function, which means it doesn't have access to any private variables.
diff --git a/labs/lab02/index.md b/labs/lab02/index.md index ed46748a9..6bfa0f343 100644 --- a/labs/lab02/index.md +++ b/labs/lab02/index.md @@ -74,7 +74,7 @@ Below is a UML diagram showing how these classes interact with each other.  -This diagram shows a list containing two elements, the integers 3 and 7. Note that there are more methods in the List and ListItr classes than what is shown above. The head and tail pointers in the List class point to dummy nodes -- they are put there to make inserting elements into the list easier. It doesn't matter what the value of the dummy nodes is set to, as it won't be used. Each ListNode points to the nodes before and after it (although the dummy nodes each have one pointer pointing to NULL). +This diagram shows a list containing two elements, the integers 3 and 7. Note that there are more methods in the List and ListItr classes than what is shown above. The head and tail pointers in the List class point to dummy nodes -- they are put there to make inserting elements into the list easier. It doesn't matter what the value of the dummy nodes is set to, as it won't be used. Each ListNode points to the nodes before and after it (although the dummy nodes each have one pointer pointing to nullptr). Thus, our doubly linked list will have only one List object and many ListNode objects (2 more than the number of elements in the list). A ListItr is a separate object, which points to one element in the list (possibly a dummy node). As you call the various methods in ListItr to move the iterator forward and backward, the node that it points to will change. @@ -117,7 +117,7 @@ as well as suggested implementation order: When beginning to test your code, chances are your program will crash unexpectedly with a message similar to `Segmentation fault (core dumped)`, commonly referred to as a _segfault_. Get prepared to see these often throughout the course, as unlike other programming languages like Java, C++ does not give any extra debugging information on a crash. In order to determine where and why your program is crashing, run your code through the debugger and look at the backtrace. -Segfaults generally indicate that you are trying to dereference a NULL or invalid pointer, so those are good things to look out for. +Segfaults generally indicate that you are trying to dereference a nullptr or invalid pointer, so those are good things to look out for. #### The constructor #### By the time the constructor finishes, we should have a functioning (but empty) list. @@ -196,7 +196,7 @@ It should also make sure that `head` and `tail` no longer point to those deleted Since we have been dynamically allocating ListNodes, we must also be responsible for deleting them to ensure we do not leak memory. There are multiple ways to iterate through the list and `delete` each ListNode -- experiment and see what makes the most sense to you.\ **Important:** once you delete a ListNode, you can no longer reliably access any of its data, such as its `next` or `previous` pointers! -To make sure you don't do this accidentally, we recommend setting each ListNode to NULL as soon as you delete it. +To make sure you don't do this accidentally, we recommend setting each ListNode to nullptr as soon as you delete it. The destructor should delete _all_ dynamically-allocated memory, as we no longer need this List instance. Thus, it makes sense that we should delete all the elements we inserted (hint: do we already have a method for that?). diff --git a/labs/lab04/index.html b/labs/lab04/index.html index b3ba908b9..564cae66e 100644 --- a/labs/lab04/index.html +++ b/labs/lab04/index.html @@ -180,7 +180,7 @@climits
will come in handy here again. For types not in climits
, you should reason about how the data is stored and the size of that type.
For some parts of this lab, it is helpful to assign a value to a variable, then inspect that variable's contents using a debugger. You can write a simple C++ program that creates the variables, and stores the appropriate value (zero, one, or NULL) into them. Compile (remember the -g
flag!), load the debugger, set a breakpoint, and start the program execution.
For some parts of this lab, it is helpful to assign a value to a variable, then inspect that variable's contents using a debugger. You can write a simple C++ program that creates the variables, and stores the appropriate value (zero, one, or nullptr) into them. Compile (remember the -g
flag!), load the debugger, set a breakpoint, and start the program execution.
When using LLDB, you can use the 'x' (for 'eXamine') command to print out the pointee of an address. Consider the C++ program that has two variables defined, int i
and int *p
. To print out the int variable i
, you would enter x &i
(as you have to enter the address of where the data is located). If p
is a pointer to a value, you would enter x p
to print out the pointee. This may print it using many more hexadecimal digits than you wanted, so you can add a parameter to the 'x' command to have it print only a certain amount:
x/xb p
: this will print the one byte at the address that is pointed to by p