Programming Exercises

I l @ ve RuBoard

Programming Exercises

  1. Modify Listing 17.2 so that it displays the movie list both in the original order and in reverse order. One approach is to modify the linked-list definition so that the list can be traversed in both directions. Another approach is to use recursion.

  2. Suppose list.h (refer to Listing 17.3) uses the following definition of a list:

     typedef struct list { Node * head;  /* points to head of list */ Node * end;   /* points to end of list  */ } List; 

    Rewrite the list.c (refer to Listing 17.5) functions to fit this definition and test the resulting code with the films3.c (refer to Listing 17.4) program.

  3. Suppose list.h (refer to Listing 17.3) uses the following definition of a list:

     #define MAXSIZE 100 typedef struct list {     Item entries[MAXSIZE];    /* array of items          */     int items;                    /* number of items in list */ } List; 

    Rewrite the list.c (refer to Listing 17.5) functions to fit this definition and test the resulting code with the films3.c (refer to Listing 17.4) program.

  4. Rewrite mall.c (refer to Listing 17.7) so that it simulates a double booth having two queues.

  5. Write a program that lets you input a string. The program then pushes the characters of the string onto a stack one by one (see Review Question 5), and then pops the characters from the stack and displays them. This results in displaying the string in reverse order.

  6. Write a function that takes three arguments: the name of an array of sorted integers, the number of elements of the array, and an integer to seek. The function returns the value 1 if the integer is in the array, and if it isn't. Have the function use the binary search technique.

  7. Write a program that opens and reads a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it occurs. After the program has read the file, it offers a menu with three choices. The first is to list all the words along with the number of occurrences. The second is to let you enter a word, and the program reports how many times the word occurred in the file. The third choice is to quit.

  8. Modify the Pet Club program so that all pets with the same name are stored in a list in the same node. When the user chooses to find a pet, the program requests the pet name and then lists all pets (along with their kinds) having that name.

I l @ ve RuBoard


C++ Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 314
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net