Extra Credit: Word Sort

Purpose

This assignment is designed to give you more practice with reading input and handling strings.

Problem Description

Write a program that sorts a series of words entered by the user and prints the resulting list, in order, to the screen.

Assume that each word is no longer than 20 ASCII characters long (and contains no spaces or control characters). Also, you may assume that there will be no more than 20 words entered. Stop reading new words when the user presses "Enter" without typing a word.

Store each word in a dynamically allocated string, using an array of pointers OR a linked list to keep track of the strings. After all the words have been read, sort the array/list and then use a loop to print the words in sorted order. You should use the insertion sort algorithm to sort the strings, although you may use any sorting algorithm other than bubble sort. Note that you can sort the array as you add the words to the array (see King, page 418).

Grading

This assignment will be worth up to 12 points based on the following distribution:

Acknowledgements

(This is Programming Project #5 in Chapter 17 of the King textbook.)