C++: Linked Lists, Stacks, and Queues

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

1/17

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.

18 Terms

1
New cards

Define Linked List

A Data structure used to implement a list of items arranged in some kind of order

2
New cards

Components of linked list

Nodes

3
New cards

first node of linked list

head pointer

4
New cards

last node of linked list

tail pointer

5
New cards

What is a NULL pointer?What library is it used in?

A NULL pointer is a C++ pointer value that can be used for a pointer that doesnt point anywhere. it is used in the <cstdlib> library

6
New cards

what is the symbol -> ?
provide an example.

member selection operator. allows you to select a member of the pointer in a class
ex: head_ptr->data() activates the data function of the node pointed to by head_ptr.

7
New cards

Why is a pointer to a node with a const keyword necessary for certain functions.

It allows a user to call a function with a pointer and not change the value of the pointer.

8
New cards

write code to implement the following function:
void list_head_insert(node*& head_ptr, const node::value_type& entry);

void list_head_insert(node*& head_ptr, const node::value_type& entry)
{node *insert_ptr;

insert_ptr = new node(entry, head_ptr);
head_ptr = insert_ptr;
}

9
New cards

write code to implement the following function:
void list_insert(node* previous_ptr, const node::value_type& entry)

void list_insert(node* previous_ptr, const node::value_type& entry)
{
insert_ptr = new node;
insert_ptr->set_data(entry)
insert_ptr->set_link( previous_ptr->link());
previous_ptr->set_link(insert_ptr);
}

10
New cards

Which of the following are better for random access?
-dynamic arrays
-Linked lists
-doubly linked lists

dynamic arrays

11
New cards

Which is better at insertion/deletion at a cursor?
-dynamic arrays?
-Linked lists?
-double linked lists?

linked lists

12
New cards

4. Answer true or false for this statement: For all possible inputs, a linear algorithm to solve a problem must perform faster than a logarithmic algorithm to solve the same problem.

FALSE

13
New cards

6. What term is used to describe an O(Logn) algorithm.
A. Constant
B. Linear
C. Logarithmic
D. Quadratic

C. logarithmic

14
New cards

9. Suppose cursor points to a node in a linked list (using the node definition with member functions called data and link). What statement changes cursor so that it points to the next node?
A. cursor++;
B. cursor = link( );
C. cursor += link( );
D. cursor = cursor->link( );

D. cursor = cursor->link( );

15
New cards

What is a Stack?

a data structure of ordered entries such that entries can be inserted and removed only one end, called the top. (first in, last out).

16
New cards

what does the function pop() do in a stack?

removes the top item from the class

17
New cards

what is stack underflow, and what is stack overflow?

underflow is the condition from trying to access an item from an empty stack.
overflow is the condition resulting from trying to push an item onto a full stack.

18
New cards

List two ways of implementing stacks.

-static implementation: using a fixed size arrray.
-dynamic implementation using a linked list.