Intro to Computer Science 2 - CSI 1440 - Baylor - Aars Final
run time
Dynamic binding takes place at ____________
the rear index
When an element is added to a queue, where is it added?
the front index
When an element is removed from a queue, where is it removed from?
in the case of Binary Search Trees, sorts the data from least to greatest
When is in-order traversal useful?
When you need to delete the tree Post-Order returns data in the order you need to delete the nodes without leaking the memory of the other nodes
When is post-order traversal useful?
sequence
A __________ container organizes data in a sequential fashion similar to an array
associative
A __________ container uses keys to rapidly access elements
children
A binary tree node's left and right pointers point to the nodes __________
sub-tree
A branch of the tree from one particular node down
abstract class
A class that cannot be instantiated
self referential data structure
A data structure that points to an object of the same type as itself
doubly linked list
A list where each node has a pointer to the node before it and the node after it
circular linked list
A list where the last node has a pointer to the first node
leaf node
A node with no children
appending
Adding a node to the end of the list
inserting
Adding a node to the list, anywhere in the list
struct Node { dataType* data; Node* next; }
How do you create a basic node?
class IntLinkedList { private: struct Node { int* data; Node* next; } Node* head; public: // insert functions etc }; in main: IntLinkedList list; list.insert(1);
How do you create a linked list?
class ExceptionName {};
How do you create an exception?
ClassName<dataType> objectName; ex. ClassName<int> objectName;
How do you instantiate a templated class object?
void functionName ( ) { if ( condition needed for function to run ) { // do something } else { throw ExceptionName(); } }
How do you throw an exception?
addEm(1, 2); OR addEm(5.69, 4.56); OR addEm( 'a' , 'b'); etc.
How would you call a templated function?
void insert ( dataType data ) { if ( head != NULL ) { // if the list is not empty Node* temp = head; while ( temp->next != NULL ) { // traverse to the end temp = temp->next; } temp->next = new Node(data); // append the new node } else { head = new Node(data); // create the first node }
How would you create an insert function for a linked list?
ostream& print ( ostream& out ) { if ( head != NULL ) { // if the list is not empty Node* temp = head; while ( temp->next != NULL) { // traverse through list out << temp->data << "->"; // print each nodes data temp = temp->next; } else { out << "List is empty!"; } out << "NULL" << endl; return out; } ex: 1->2->3->NULL
How would you print a linked list?
template <class T> class ClassName { private: // mock data T* data; T array [ ]; public: // mock methods T addEm(T one, T two) { return one + two; } // etc. };
How would you write a templated class?
template <class T> T addEm (T one, T two) { return one + two; }
How would you write a templated function?
virtual function
In order to use dynamic binding, a member function of a class needs to be declared as a __________
iterators
Pointer-like objects used to access information stored in a container
compile time
Static binding takes place at ___________
composition
The "has-a" relation between classes is best implemented using the mechanism of class __________
inheritance
The "is-a" relation between classes is best implemented using the mechanism of class ___________
catch
The __________ block handles an exception
try
The __________ block should enclose code that might directly or indirectly cause an exception to be thrown
list head
The __________ points to the first node in a linked list
polymorphism
The ability of code to execute differently depending on the type of data is called ___________
throw point
The line containing a throw statement
in-order pre-order post-order
Three types of binary tree traversal
NULL
To indicate that a linked list is empty, you should set the list head pointer to
traversing
Traveling through a list
left, me, right
What are the steps for in-order traversal?
left, right, me
What are the steps for post-order traversal?
me, left, right
What are the steps for pre-order traversal?
queue
What data structure uses FIFO?
stack
What data structure uses LIFO?
first in, first out
What does FIFO mean?
last in, first out
What does LIFO mean?
Node (dataType data, Node* next = NULL ) { this->data = data; this->next = next; }
What does a Node struct constructor look like?
A recursive delete that will delete all nodes. temp->next must be set to NULL in order to prevent the entire list being deleted
What does a destructor in a Node struct do?
try { functionName( ); } catch ( ExceptionName ) { // print error or close program }
What does a try-catch block look like?
Removes and returns the value on the top of the stack
What does popping off a stack do?
Stores a value on the top of the stack
What does pushing onto a stack do?
the last element in
What element is retrieved from a stack by the pop operation?
a stack with dynamic size, often implemented as a linked list
What is a dynamic stack?
a stack with a fixed size, often an array
What is a static stack?
removing an element from the front of the queue
What is dequeuing?
inserting an element at the rear of the queue
What is enqueuing?
All methods must be defined in the header file
What is the downside of a templated class?
root node
What is the first node in a binary tree called?
All virtual methods of the parent abstract class must be defined in the derived class
What must be done before a derived class object of an abstract class can be instantiated?
(in insert function for list with data) Node* temp = head; // traverse to end temp->next = new Node( ); // allocate memory temp = temp->next; // move to end temp->next = NULL; temp->data = data; // insert the data (in insert function for empty list) head = new Node( ); // allocate memory head->next = NULL; head->data = data; // insert the data
What would you do if you did not have a Node constructor?
When you need to create a copy of the tree Pre-Order traversal returns the data in the order it came in
When is pre-order traversal useful?
type parameter
When writing function or class templates, you use a __________ to specify a generic data type
So that you can use the same functions/class for many different data types. ex. function that adds two things together: integers, doubles, strings, chars
Why would you create a templated function/class?
abstract class
a class with at least one pure virtual member function
virtual function
a member function of a class that is not implemented