不好意思,朋友的问题,本人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.
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.
解决方案 »
- 求教用BigInteger处理的大数阶乘,能算到10000!
- 数据库连接不报错,却没得到数据???
- 关于api过时的问题 请教
- split 对“.”分割无效?
- 什么样的java开发工具你认为最好,最有前途Borland Eclipse JDeveloper NetBeans IntelliJ Microsoft Visual J++
- 功力不够!请问这个怎么写,有关类和对象的!
- 现在软件公司写java都用什么工具?
- java可以不可以和javascript一起学啊?会不会混淆啊?
- 得分就是这么容易!
- № 1 : 这个菜单为什么显示不出来阿,编译时又没有报错???!!!
- 新手求急:如何在jsp页面中调用自己编译好的jar包?
- 还是问一下这个问题吧,说不定有好办法
// 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]