You are on page 1of 5

C++ Data Structures Problems 1) Write a small program that will check for balancing symbols in C++.

Look for: /* */ ( ) [ ] { } See if you can display an error message that will describe the problem and point to the
possible problem section of code

2) Implement the following specification for an interger function in the client program that returns the number of items in a queue. The queue is unchanged.

int Length(QueType queue) Function: Precondition: Post conditions: Determines the number of items in the queue. queue has been initialized. queue is unchanged. Function value = number of items in queue.

3) free 7 nodes [0] [1] [2] [3] [4] [5] .info John Mark Nell Naomi .next 4 5 3 NUL 8 6

[6] [7] [8] [9] list 1 0 list 2 1

Robert Susan Susanne

NUL 2 9 NUL

Figure 6.19 (top) An array with three lists (including the free list) a. b. c. d. e. What What elements are in the list pointed to by list1? What elements are in list pointed to by list2? What array positions (indexes) are part of the free space list? What would the array look like after the deletion of Nell from the first list? What would the array look like after the insertion of Anne into the second list? Assume that before the insertion the array is as pictured in Figure 6.19.

4) A sequential search member function of SortedType has the following prototype Void SortedType: :Search(int value, bool& found): a. Write the function definition as a recursive search, assuming a linked list implementation b. Write the function definition as a recursive search, assuming an array-based implementation. 5) Choose one question not both Write a program to take n elements and insert them into a heap one by one. Include a function to print out the elements in the heap. Write a program to take n elements and insert them into a binary tree. Include a function to print out the elements in the tree.
Show the order in which the nodes in the tree are processed by

6)

a) an inorder traversal of the tree.

b) a postorder traversal of the tree. c) a preorder traversal of the tree.

Use the following specification of a directed graph for question 13. ZooGraph = (V, E) V(ZooGraph) = {dog, cat, animal, vertebrate, oyster, shellfish, invertabrate, crab, poodle, monkey, banana, dalmation, dachshund} E(ZooGraph) = { (vertabrate, animal, vertebrate, animal), (dog, vertebrate), (cat, vertebrate), (monkey, vertebrate), (shellfish, invertebrate), (crab, shellfish), (monkey, vertebrate), (shellfish, invertebrate), (crab, shellfish), (oyster, shelfish), (poodle, dog), (dalmatian, dog), (dachshund, dog) }. 8) To tell if one element in ZooGraph. Store the vertices in alphabetical order. For a path between them. Show whether the following statements are true, using the picture or adjacency matrix.

a. dalmatian X dog b. dalmatian X vertebrate c. dalmatian X poodle d. banana X invertebrate e. oyster X invertebrate. f. 9) Monkey X invertebrate

b. is

Selectionsort not Selectsort

You might also like