-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathList.java
More file actions
115 lines (113 loc) · 4 KB
/
List.java
File metadata and controls
115 lines (113 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import java.io.PrintWriter;
public interface List<T> {
void insert(T newElement) throws ListException;
/*
* Precondition: List is not full and newElement is not null.
* PostCondition:
* Inserts newElement into a list after the cursor. If the list is empty,newElement is inserted as the first(and only)element in the list.
* In either case(empty or not empty),moves the cursor to newElement.
* If there is not enough space in the list, throw a ListException exception.
* ListException is a custom Exception class which you should define it.
*/
void remove();
/*
* Precondition:
* List is not empty.
* PostCondition:
* Removes the element marked by the cursor from a list.If the resulting list is not empty,
* then moves the cursor to the element that followed the deleted element.If the deleted element
* was at the end of the list,then moves the cursor to the element at the beginning of the list.
*
*/
void replace(T newElement);
/*
* Precondition:
* List is not empty and newElement is not null.
* PostCondition:
* Replaces the element marked by the cursor with newElement. The cursor remains at newElement.
*/
void clear();
/*
* Precondition:
* None
* PostCondition:
* Removes all the elements in a list.
*/
boolean isEmpty();
/*
* Precondition:
* None
* PostCondition:
* Returns true if a list is empty. Otherwise , returns false.
*/
boolean isFull();
/*
* Precondition:
* None
* PostCondition:
* Returns true if a list is full. Otherwise, returns false.
*/
boolean gotoBeginning();
/*
* Precondition:
* None
* PostCondition:
* If a list is not empty, then moves the cursor to the beginning of
* the list and returns true.Otherwise,returns false.
*/
boolean gotoEnd();
/*
* Precondition:
* None
* PostCondition:
* If a list is not empty,then moves the cursor to the end of the list
* and returns true.Otherwise, returns false.
*/
boolean gotoNext();
/*
* Precondition:
* List is not empty.
* PostCondition:
* If the cursor is not at the end of a list,then moves the cursor to the
* next element in the list and return true.Otherwise,returns false.
*/
boolean gotoPrev();
/*
* Precondition:
* List is not empty.
* PostCondition:
* If the cursor is not at the beginning of a list,then moves the cursor to
* the preceding element in the list and returns true.Otherwise,returns false.
*/
T getCursor();
/*
* Precondition:
* List is not empty.
* PostCondition:
* Returns a copy of the element marked by the cursor.
*/
void showStructure(PrintWriter pw);
/*
* Precondition:
* None
* PostCondition:
* Outputs the elements in a list and the value of cursor. If the list is empty,outputs "Empty list".
* Note that this operation is intended for testing/debugging purpose only.
*/
void moveToNth(int n);
/*
* Precondition:
* List contains at least n + 1 elements.
* Postcondition:
* Removes the element marked by the cursor from a list and reinserts it as the nth element in the list, where the elements are numbered from beginning to end, starting with zero. Moves the cursor to the moved element.
*/
boolean find(T searchElement);
class ListException extends Exception {
}
/*
* Precondition:
* List is not empty.
* Postcondition:
* Searches a list for searchElement. Begins the search with the element marked by the cursor. Moves the cursor through the list until either searchElement is found (returns true) or the end of the list is reached without finding searchElement (returns false). Leaves the cursor at the last element visited during the search.
*/
}