Because dequeues are similar to vectors, this assignment will be more of a generic algorithm assignment than a dequeue assignment; that is, you should be looking to cram your code full of generic algorithms rather than dequeues (although, of course, a dequeue or two wouldn't hurt).
In the previous assignment you implemented a program calledreadmbox
, which responded to two commands: a message number n, which printed message n if it exists, and the quit commandq
, which quit the program. In this assignment you'll add theorder
command toreadmbox
's command repertoire.The
order
command re-orders the sequence of messages presented to thereadmbox
user. Theorder
command format iswhere [ a ] means a is optional. field is a word with no interpretation placed on it.order
[ field word ]The pair field word is called a search pattern. A search pattern matches a header field if the header field has field as its label and word as a word in its text-line. For example, the search pattern "Subject Urgent" matches the header field
Subject: Ugent!! Read at once!!but matches neither of the header fieldsSubject: About your last bill...because the text-line doesn't contain "Urgent" norDisposition: Urgentbecause the label isn't "Subject". A search pattern matches a message if it matches at least one of the header fields in the message.The command
order field wordre-orders the message list so that messages which match the search pattern are presented to the user before messages which don't match the search pattern. For example, suppose the current state of the message list inreadmbox
is1 2* 3 4* 5* 6where each number is a message number and an asterisk (*) represents a message which matches the search pattern. Thenorder
would re-order the message list to2* 4* 5* 1 3 6so that what was the second message becomes the first message, what was the fourth message becomes the second message and so on. Notice that the previous message-list order is preserved within each group of matching or non-matching messages. For example,order
would be incorrect if it re-ordered the message list as4* 2* 5* 6 3 1such sorts are known as stable sorts.The command
orderresets the message list to the order it had whenreadmbox
was started.
This page last modified on 4 July 2000.