April:03(Fri)
Acknowledgement: Some of these exercises are derived from "A Practical Introduction to Data Structures and Algorithm Analysis" by Clifford A. Shaffer.
linkList.java code,
and suppose at some point
in main(),
theList
contains five elements, as follows:
[V, W, X, Y, Z]E.g. V might be {88, 8.99}, W might be {77, 7.99}, etc. Write a series of Java statements to be used in
main()
to delete just the third element here, X,
so
theList
will be as follows.
[V, W, Y, Z]Do NOT use
delete(int key)
which is supposed to be in the second linked-list
program linkList2.java;
use only methods provided in
the first linked-list program.
linkList2.java
with a method interchange_with_next(int key)
to interchange
the element specified by key
with the one immediately
following it in the list.
(Note that you can do this
without changing any next-links.
Consider an analogous situation: to swap elements in an array,
do you need to really make any changes to the structure of the array itself?)
linkList2.java .
key
and a following element.
class LinkList
a method concatenate()
that takes another
LinkList
as an argument
and returns the result of
adding the given list to the end of the one
for which the method is invoked.
E.g.
if
list1 is [A,B,C]
and
list2 is [D,E,F],
then list1.concatenate(list2)
should return [A,B,C,D,E,F].
linkList2.java .
| | | | | | | | | | | | | 4 | | | | | push(6) | 6 | push(4) | 6 | pop():4 | 6 | ... +---+ +---+ +---+ +---+