CS Logo

Homework 6

 

This homework is due on Sunday.

 

Datastructures and Dynamic Arrays

Multiple Choice (4 points each)

 

1. Which of the following correctly declares an array?
A. int anarray[10];
B. int anarray;
C. anarray{10};
D. array anarray[10];
 

2. What is the index number of the last element of an array with 29 elements?
A. 29
B. 28
C. 0
D. Programmer-defined
 

3. Which of the following is a two-dimensional array?
A. array anarray[20][20];
B. int anarray[20][20];
C. int array[20, 20];
D. char array[20];
 

4. Which of the following correctly accesses the seventh element stored in foo, an array with 100 elements?
A. foo[6];
B. foo[7];
C. foo(7);
D. foo;
 

5. Which of the following gives the memory address of the first element in array foo?
A. foo[0];
B. foo;
C. &foo;
D. foo[1];

 

6. (30 points) Implement a stack using an array. Let the user specify the size of the array to use.

 

You will need to specify the functions push and pop that make the array behave like a stack.

 

You must handle attempts to add items to the stack when the array is full, but you can handle that case however you wish.

 

7. (30 points) Implement a queue using an array.
Let the user specify the size of the array to use.

 

You will need to specify the functions push and pop that make the array behave like a queue.

 

You must handle attempts to add items to the queue when the array is full, but you can handle that case however you wish.