CS Week 7 - Linked Lists Flashcards

1
Q

pointer

A

a variable that contains a memory address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Dynamically allocated array

A

an array whose size can change during runtime

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when a vector is created

A

–The class internally dynamically allocates an array with an initial size
–If the number of elements added to the vector exceeds the capacity, class with dynamically allocate a new array with an increased size
–Contents of the array are copied into the new larger array
–Each time the internal array is dynamically allocated, array’s location in memory will change
–Vector class uses a pointer to store the memory location of the internal array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Vector insert/erase performance problem

A

For a vector with thousands of elements, a single call to insert() or erase() can require thousands of instructions and cause the program to run very slowly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Linked list

A

consists of items that contain both data and a pointer - a link- to the next list item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

this pointer

A

when a class member function is called on an object, a pointer to the object is automatically passed to the member function as an implicit parameter

  • Enables access to an object’s data members within the object’s class member functions

-A data member can be accessed using this and the member access operator for a pointer ->

-This pointer clearly indicated that an objects data member is being accessed, which is needed if a member function’s parameter has the same variable name as the data member

this-> dataMember

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Singly-linked list

A

a data structure for implementing a list ADT, where each node has data and a pointer to the next node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

head

A

singly-linked list’s first node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

tail

A

singly-linked list’s last node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

positional list

A

a list where elements contain pointers to the next and/or previous elements in the list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

null

A

a special value indicating a pointer points to nothing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Append

A

inserts the new node after the list’s tail node

Appending to empty list: if list’s head pointer is null(empty), algorithm points the list’s head and tail pointers to the new node

Append to non-empty list: if the list’s head pointer is not null (not empty), algorithm points the tail node’s next pointer and the list’s tail pointer to the new node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Prepend

A

inserts the new node before the list’s head node

Prepend to empty list-if the list’s head pointer is null (empty), algorithm points the list’s head and tail pointers to the new node

Prepend to non-empty list- if the list’s head pointer is not null (not empty), algorithm points the new node’s next pointer to the head node, and then points the list’s head pointer to the new node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

InsertAfter

A

inserts the new node after a provided existing list node

curNode is a pointer to an existing list node, but can be null when inserting into an empty list

Insert as list’s first node- if the list’s head pointer is null, algorithm points the list’s head and tail pointers to the new node

Insert after the list’s tail node- if the list’s head pointer is not null and curNode points to the list’s tail node, algorithm points the tail node’s next pointer and the list’s tail pointer to the new node

Insert in middle of list- if the list’s head pointer is not null and curNode does not point to the list’s tail node, algorithm points the new node’s next pointer to curNode’s next node, and then points curNode’s next pointer to the new node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

RemoveAfter

A

removes the node after the specified list node

Exiting node must be specified because each node in a singly-linked list only maintains a pointer to the next node

curNode parameter - existing node

Remove list’s head node- (special case) if curNode is null, algorithm points sucNode to the head node’s next node, and points the list’s head pointer to sucNode. If sucNode is null, the only list node was removed, so the list’s tail pointer is pointed to null (indicating list is now empty)

Remove node after curNode- if curNode’s next pointer is not null (a node after curNode exists), algorithm points sucNode to the node after curNode’s next node. Then curNode’s next pointer is pointed to sucNode. If sucNode is null, the list’s tail node was removed, so algorithm points the list’s tail pointer to curNode (the new tail node)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Destructor

A

a special class member function that is called automatically when a variable of that class type is destroyed

17
Q

When a destructor is called

A

Using the delete operator on an object allocated with the new operator calls the destructor, in previous example

For an object that is not declared by reference or by pointer, the object’s destructor is called automatically when the object goes out of scope

18
Q

copy constructor

A

a constructor that is automatically called when an object of the class type is passed by value to a function and when an object is initialized by copying another object during declaration

Called with a single pass-by-reference argument of the class type, representing an original object to be copied to the newly-created object

MyClass (const MyClass& orgiObject);

use to not delete data twice

19
Q

deep copy

A

copy constructor makes a copy of all data members (including pointers)

20
Q

memberwise copy

A

opies each member using assignment: newObj.member1 = origObj.member1

happens if no copy constructor defined

21
Q

shallow copy

A

creating a copy of an object by copying only the data member’s values

22
Q

overloading the assignment operator

A

Implementation of the assignment operator iterates through each member of the source object

Each non-pointer member is copied directly from source member to destination member

For each pointer member, new memory is allocated, the source’s referenced data is copied to the new memory, and a pointer to the new member is assigned as the destination member

23
Q

destructor

A

a class member that is automatically called when an object of the class is destroyed, such as when the object goes out of scope or is explicitly destroyed as in delete someObj;

24
Q

copy constructor

A

another version of a constructor that can be called with a single pass by reference argument

Automatically called when an object is passed by value to a function, such as the function someFunction(MyClass localObject) and the call someFunction(anotherObj)

Automatically called when an object is initialized when declared such as MyClass classObj1 = classObj2;

Automatically called when an object is initialized when allocated “new” as in newObjPtr = new MyClass(classObj2);

25
Q

copy assignment operator

A

the assignment operator “=” can be overloaded for a class via a member function, known as the copy assignment operator

Overloads the built-in function “operator=”

The member function having a reference parameter of the class type and returning a reference to the class type

26
Q

rule of three

A

describes a practice that if a programmer explicitly defines any one of those three special member function, then the programmer should explicitly define all three

27
Q

the big three

A

destructor, copy constructor, copy assignment operator

28
Q

look over notebook and google doc

A