(Ch. 17) Understanding Linked Lists and Their Operations

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/30

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

31 Terms

1
New cards

linked list

A linked list is a series of connected nodes where each node contains data and a pointer to the next node.

2
New cards

linked list node parts

A data member and a pointer to the next node.

3
New cards

list head

A pointer that points to the first node in the list.

4
New cards

end of a linked list

By having the last node's pointer point to nullptr.

5
New cards

self-referential data structure

A structure that includes a pointer to another structure of the same type.

6
New cards

advantages of linked lists

Linked lists can grow/shrink dynamically and insert/delete elements more efficiently.

7
New cards

basic linked list operations

Appending, inserting, deleting, traversing, and destroying nodes.

8
New cards

appendNode function

It allocates a new node, stores the value, and attaches it at the end of the list.

9
New cards

traversing a linked list

Visiting each node from the head to the end of the list using their pointers.

10
New cards

displayList() function

To traverse the list and output each node's data.

11
New cards

inserting into a sorted linked list

By finding the correct position and updating the pointers accordingly.

12
New cards

previousNode pointer in insertNode

It keeps track of the node before the insertion point.

13
New cards

deleteNode function

It bypasses the node using pointers and then deletes it from memory.

14
New cards

destructor in a linked list class

It deallocates memory by deleting all nodes to prevent memory leaks.

15
New cards

doubly linked list

A list where each node has pointers to both the previous and next nodes.

16
New cards

circular linked list

A list where the last node points back to the first node.

17
New cards

STL container for doubly linked list

The list container in the Standard Template Library (STL).

18
New cards

STL list::reverse() function

It reverses the order of elements in the list.

19
New cards

list::push_front(x)

It inserts the value x at the beginning of the list.

20
New cards

deleting a node from a linked list

(1) Remove the node from the list by adjusting pointers, and (2) delete it from memory.

21
New cards

What happens if you forget to update previous->next when inserting?

Node is disconnected; list breaks.

22
New cards

What happens in: head = newNode; delete newNode;

Head becomes a dangling pointer.

23
New cards

What does displayList(head) print if head is nullptr?

Nothing.

24
New cards

Why use Node*& in insert/delete functions?

It allows modifying the actual pointer passed in.

25
New cards

Why doesn't insert(Node* head) work?

Pointer is passed by value — changes are lost.

26
New cards

What happens if deleteNode can't find the value?

Nothing happens if code checks for nullptr.

27
New cards

What happens if you delete head without updating it?

Dangling pointer — undefined behavior.

28
New cards

How do you prevent infinite loop in list traversal?

Use while(current != nullptr).

29
New cards

What's the risk in circular linked lists?

Potential infinite loop — must break manually.

30
New cards

What happens if prev or next isn't updated in a doubly linked list?

Corrupts one or both traversal directions.

31
New cards

What does list::reverse() do?

Reverses the element order in the STL list.