Java代写:实现doubly linked list

用java实现doubly linked list来储存数据。

CSCI 136 Assignment 4

Description

A common need with computers is to store massive amounts of information about an object. A good example is storing graphic images. In order to save space both on disks and in transmission of information across the internet, researchers have designed algorithms to compress data. In this lab you will learn one of these compression techniques.

A graphic image can be represented by a two dimensional array of information about the colors of various picture elements (or pixels). At high resolution the image may be composed of 1000 rows and 1000 columns of information, leading to the need to store information on 1,000,000 pixels per image. Needless to say this creates serious problems for storing and transmitting these images. However most images tend to have contiguous groups of pixels, each of which are the same color. We can take advantage of this by trying to encode information about the entire block in a relatively efficient manner.

The basic idea of our encoding will be to represent a block of pixels with the same color by simply recording the first place where we encounter the new color and only recording information when we see a new color. For instance suppose we have the following table of information (where we will imagine each number represents a color):

2 2 2 3 3
2 3 3 3 3
3 1 1 1 3

If we imagine tracing through the table from left to right starting with the top row and going through successive rows, then we notice that we only need to record the following entries:

2 - - 3 -
2 3 - - -
- 1 - - 3

Rather than recording this in a two-dimensional table, it will now generally be more efficient to keep this information in a linear list:

(0,0);2 (0,3);3 (1,0);2 (1,1);3 (2,1);1 (2,4);3

How might this list be implemented? Perhaps as a vector or some sort of linked list. Before we make a decision, let’s consider one more thing. So far, you’ve probably been thinking that you are given a static image that needs to be represented in compressed form. That’s part of the story. But consider also the possibility that someone might want to edit the image, thereby changing its pixels. As pixels change, we need to be sure our representation of the compressed image changes as well. Therefore, we need a form of list that will allow us to move freely backwards and forwards through it without always having to begin at the head or the tail.

In the Assignments folder on Cider Press, you will find the folder “Color Matrix Demo”. The demo program will display a 12x12 matrix of “pixels” that you may edit. The color of a “pixel” may be changed by clicking on it. The currently active color (selected by clicking on one of the three color choices on the right of the screen), will be assigned to that “pixel”. As you edit the 12x12 grid, you will see the corresponding list entries in the lower part of the screen.

For this assignment, you are to build the data structure that will allow us to represent such compressed tables. You will do the assignment in two stages:

  1. First extend DoublyLinkedList to a class CurDoublyLinkedList. This class should have extra capability to move to any desired element of the list (called the current element) and then either add a new node after this element or remove the current element. Your new class should support all of the old methods of Lists as well as first(), last(), next(), back(), isOffRight(), isOffLeft(), getCurrent(), addAfterCurrent(Object value), and deleteCurrent(). Specifications for these methods can also be found on Cider Press in the Assignments folder.
  2. Once you’ve thoroughly tested the class CurDoublyLinkedList, you should add it to my demo program. This will provide you with an additional opportunity to test your code. Remember that in implementing CurDoublyLinkedList, you are providing a data structure that should be of general use for many applications, only one of which is my demo program.

I have provided you with a lot of code here, but you will find that much of the omitted code is quite tricky. This project will require you to be very careful in developing the code for the methods.

Goals

The goals are to practice implementing linked lists and to learn about inheritence.

What to hand in

Bring a complete design to lab on Wednesday. Your design document should consist of pseudocode for all the methods to be implemented in CurDoublyLinkedList. I will be expecting to see the complete logic of the methods. Remember that you must draw pictures and look at all possible special cases in order to get these right.

This lab will be due on Sunday, March 5 at 11:59 pm for those in a Wednesday lab and on Monday, March 6 for those in the Thursday lab. For this lab, you should turn in a folder containing your CurDoublyLinkedList class, including your test code. As usual, drop it off in the CSCI 136 drop-off folder.

kamisama wechat
KamiSama