### CSAS1112 - Practice Exam 2

This practice exams lists some sample questions, covering the topics that will be covered in the actual exam. The actual exam may or may not contain questions similar to this practice exam, but the format of the actual exam will be very similar to this practice one. However, this practice exam is somewhat longer than the actual exam.
There may be some more questions later. Please check back Monday before class, if possible. If there are new questions, it will be indicated here.

1. Define the following terms: List, Stack, Queue, FIFO, LIFO. What operations are part of a Stack ? What operations are part of a Queue ? What does the keywords new and delete do ? What is a pointer ? What data type can a pointer point to ? How much memory does a pointer, a double, an integer, and a char use in Turbo C++ for DOS ? What are the simularities between an array and a list ? What are the differences between a array and a list ?

2. Decide which of the following statements are true and which are false:

 A double occupies more memory than an int A pointer to a double ocupies more memory than a pointer to an int If the characters 'b', 'e', 'r', 't' are first pushed into a stack, then popped from the stack, the result will spell 'bert'. If the characters 'b', 'e', 'r', 't' are first enqueued into a queue, then dequeued from the queue, the result will spell 'bert'. When considering a stack, a queue, and a list, the queue is most similar to an array. In a stack of size N, one needs to access N / 2 nodes to retrieve the middle node [trick questions]

3. List the output of the following program segment. If an error is contained in the program, please mark and explain the error. For the rest of the program, assume that all lines with an error are removed from the program.

```#include <iostream.h>

class Node
{
public: double data;
public: Node *next;
};

int main(void)
{
double *px, *py;
double x, y;
Node *p, *q, *r;

x = 9.5;
y = -2.0;
px = 8.6;
*px = 10.0;
*x = *px;
x = *px;
py = &y;
p = new Node(); q = new Node(); r = new Node();
p->data = 1.0;
q->data = 2.0;
r->data = 3.0;
p->next = q;
q->next = r;
r->next = p;
cout << *px << endl;
cout << x << endl;
cout << *py << endl;
cout << q->next;
cout << p->next->next->next->next->data << endl;
delete q;
cout << p->next->next->next->next->data << endl;
return 0;
}```

4. Write some sample code for the following situation:

 Delete a node in a double-linked list, as indicated in the following picture. You do not have to provide a complete function or class, nor do you need to worry about special cases such as deleting the only node. Note: each node has three fields, a prior and next pointer, and a data field.

 Insert a node in a double-linked list, as indicated in the following picture. You do not have to provide a complete function or class, nor do you need to worry about special cases such as inserting the first node. Note: each node has three fields, a prior and next pointer, and a data field.