1.

Using the "cursor in a word processor" notation from the book, indicate the contents of the list and the iterator position after each step in the code below.

      LinkedList letters = new LinkedList();
      ListIterator iterator = letters.listIterator();
      iterator.add("A");
      iterator.addFirst("B");
      iterator.add("C");
      iterator.add("D");
      iterator.addFirst("E");
      iterator.next();
      iterator.next();
      iterator.remove();


Answer:


2.

Instead of using a LinkedList to remove and add items in the middle of a list, why does Java provide a ListIterator class?


Answer:


3.

When you use a ListIterator to remove an object from a LinkedList, where does the iterator point after the object is removed?


Answer:


4.

If you create a circularly linked list with a single reference (singly linked), which direction should the links point, to the right or to the left? Does it matter? Why?

Assuming that the links point to the right, that the left most element in the list is the "first" element, and that most of the activity is at the left and right ends of the list, does it matter where the (external) reference to the circularly linked list points? Why?


Answer:


5.

Without using Java's LinkedList class, create a doubly linked list containing strings. You do not need to implement delete operations (yet), but you must be able to insert items and traverse the list.

Your list should be able to insert a string at the beginning of the list, the end of the list, and at any other point in the list.


Answer:


6.

Without using Java's LinkedList class, create a doubly linked list containing strings. You must implement insert and delete operations and be able to traverse the list.

Your list should be able to insert a string at the beginning of the list, the end of the list, and at any other point in the list.

Your list should also be able to delete a string at the beginning of the list, the end of the list, and at any other point in the list.


Answer:


7.

In delete operations, most singly linked list implementations delete the current node. Implement a singly linked list that includes methods to delete the node after the current node or before the current node.


Answer:


8.

Modify your memo program or create a new program to read, save, insert, and delete memos using a linked list.

Create a Memo object. The memo object should have fields to store a topic, a date stamp, and the memo text. Allow a user to enter multiple memos, supplying the topic and message. Your program should provide the date stamp using the java.util.Date object (creating a Date object with no arguments initializes the object to the current time and date).

Let the user choose the file name to save the memos to (or read from).

When the user chooses a file to open, display a numbered list of topics and dates. The user can view a memo by choosing the number of the memo. While viewing a memo, the user can choose to delete the memo.

Save the file as an object stream.


Answer:


9.

1. Describe the abstract concept of a stack.
2 .Describe two concrete implementations of a stack.


Answer:


10.

You are assigned to write a program to schedule appointments for a doctor's office. An appointment is scheduled every half an hour from 8 a.m. to 4 p.m., with no appointments between 12 p.m. and 1 p.m. Not all times may be scheduled, and some times may be double-booked. You must be able to delete and add appointments at anytime. Would you use a linked list or an array to store appointments? Why?


Answer:


11.

When performing a binary search, is it more appropriate to use an array or a linked list? Why?


Answer:


12.

When performing a binary search, either two questions or one question can be asked. If two questions are asked, they might be

   1. Has the desired element been found? And, if not,
   2. Is the current element less than the desired element?

If one question is asked, it might be

   1. Is the current element less than the desired element?

In both cases, it is necessary to determine if any part of the list remains to be examined. What are the advantages and disadvantages of the two-question approach?


Answer:


13.

A deque can be thought of as a double-ended stack or a double-ended queue. Items can be inserted or removed from either end. Write an implementation of a deque.


Answer:


14.

Implement two stacks of type Object, one using an array, and one using a linked list.


Answer:


15.

Implement two queues of type Object, one using an array, and one using a linked list.


Answer:


16.

Create a program that keeps track of the weekend's chores and opportunities. Put the chores and opportunities in a stack, so that the last one in is the first one out, meaning that it needs to be completed first. Now put the same chores and opportunities in a queue in the same order, so the first one in is the first one out. In both cases, as the weekend progresses, new chores and opportunities come along which are put in the stack (or queue) after a certain number of chores and opportunities have been completed. The number of chores and opportunities for the weekend should be at least eight. Print out the chores and opportunities in the order in which they are completed using a stack, and then using a queue.


Answer:


17.

A family of four (Mom, Dad, Tom, and Will) has twelve dinner plates in a stack on the shelf. On Monday, the Nielsons came for dinner and eight plates were used. On Tuesday, everyone was home and four plates were used. On Wednesday, Mom and Dad went sailing while Tom and Will went to a friend's house, so no plates were used. On Thursday, Tom had soccer practice and three plates were used. On Friday, Will had karate lessons, so three plates were used again.

Write a program with a GUI to simulate the problem above. Cycle through the days and allow a user to enter the number of plates used. Display counters for each plate to indicate how many times each plate was used.


Answer:


18.

A couple has a monthly surplus of $700 that is set aside for discretionary spending. Any surplus that is not used is put in a special account for subsequent discretionary spending. The account balance was $0 in January. In April, the couple decided to purchase a new couch that cost $1200. In May they decided to purchase a weaving loom that cost $2000. In August, they decided to purchase a sailboat for $11,000. In December, they decided to purchase a season pass for the local cross-country ski resort for $200. Items for which there are insufficient funds remain in the queue until sufficient funds become available.

Write a program to simulate the spending and savings of this couple. Allow a user to enter the amount of discretionary money that is set aside each month. Also allow the user to enter items to be purchased each month.

Considering items in the queue each month of the year,
   1. What is the largest surplus accumulated in the special account for discretionary spending?
   2. What is the largest deficiency for items for which there are insufficient funds?


Answer: