不好意思,朋友的问题,本人Java只略懂皮毛,加之E文很烂,所以只得求各位达人了:
0. (0 s) This is a preliminary exercise, necessary for other exercises.
Download the source codes associated with the textbook: ¯le progs.zip from
http://www.cise.ufl.edu/ sahni/dsaaj/
Expand (unzip) the ¯les.
Test that you can compile and run programs. For example, executing the following commands
in the directory where you expanded ¯le progs.zip
% javac dataStructures/ArrayLinearList.java
% java dataStructures/ArrayLinearList
should give the output as in the slides for Week 3.1. (10 s) Consider the following instance of the linear list data structure:
(a; b; c; d; e):
Apply to this list the following sequence of operations:
1. add(2; f);
2. output();
3. add(2; g);
4. output();
5. add(indexOf(d); h);
6. output();
7. remove(4)
8. output();
Show the list returned by each output operation.2. (10 s) Substitute in the abstract class LinearListAsAbstractClass the abstract method
toString() with a non-abstract ¯nal method toString().
The new method should return a string in the same format as the string returned by the
toString() method in the ArrayLinearList class.3. (10 s) Measure the run time of the following two sequences of n operations add of class
ArrayLinearList:
(a) each operation add inserts a new element at the beginning of the list;
(b) each operation add puts a new element at the end of the current list.
Each sequence should start with an empty list. Keep doubling n (the number of operations add)
to observe the rate of growth of the runing time.
Show the source codes of your tests.
CS1DST: Data Structures, 2005/6 Coursework 1 2
Give two tables (one for each of the above two types of sequences of operations add) indicating
the rate of growth of the running time.
The analysis of the method add implies that the running time of one of the sequences of operations
add is £(n) while the other is £(n2). Which sequence of operations add has the running time
£(n) and which has the running time £(n2)? Justify your answer.
Do the actual running times you have observed in your tests con¯rm the above rates of growth?
Explain.4. (0 s) This is an additional, challenging exercise, which will not be ed. Do not submit
solutions.
Method perm in class Permutation (Week 1) generates all permutations but not necessary in a
lexicographic order.
For example, command
% java Permutation a b c
generates all permutations of sequence (a, b, c) in the following order:
a b c
a c b
b a c
b c a
c b a
c a b
while the lexicographic order is:
a b c
a c b
b a c
b c a
c a b
c b a
Modify method perm so that it generates permutations in the lexicographic order.

解决方案 »

  1.   

    第一题:import java.util.ArrayList;public class T3 { public static void main(String[] args) {
    // TODO Auto-generated method stub
    ArrayList aa = new ArrayList();
    aa.add("a");
    aa.add("b");
    aa.add("c");
    aa.add("d");
    aa.add("e");

    aa.add(2, "f");
    System.out.println(aa);
    aa.add(2, "g");
    System.out.println(aa);
    aa.add(aa.indexOf("d"), "h");
    System.out.println(aa);
    aa.remove(4);
    System.out.println(aa);
    }
    }答案:[a, b, f, c, d, e]
    [a, b, g, f, c, d, e]
    [a, b, g, f, c, h, d, e]
    [a, b, g, f, h, d, e]
      

  2.   

    第二题太无聊了不想做题目大意是给 ArrayList 写个 toString() 的方法但是打印出来的内容要和原来一样