mirror of
https://git.adityakumar.xyz/data-structures.git
synced 2024-12-22 19:52:52 +00:00
50 lines
1.7 KiB
Java
50 lines
1.7 KiB
Java
|
/** List ADT */
|
||
|
public interface List<T> {
|
||
|
/** Remove all contents from the list, so it is once again empty. Client is responsible for reaclaiming storage used by the list elements. */
|
||
|
public void clear();
|
||
|
|
||
|
/** Insert an element at the current location. The client must ensure that the list's capacity is not exceeded.
|
||
|
@param item The element to be inserted. */
|
||
|
public void insert(T item);
|
||
|
|
||
|
/** Append an element at the end of the list. The client must ensure that the list's capacity is not exceeded.
|
||
|
@param item The element to be appended. */
|
||
|
public void append(T item);
|
||
|
|
||
|
/** Remove and return the current element.
|
||
|
@return The element that was removed. */
|
||
|
public T remove();
|
||
|
|
||
|
/** Set the current position to the start of the list */
|
||
|
public void moveToStart();
|
||
|
|
||
|
/** Set the current position to the end of the list */
|
||
|
public void moveToEnd();
|
||
|
/** Move the current position one step left. No change if already at beginning. */
|
||
|
public void prev();
|
||
|
|
||
|
/** Move the current position one step right. No change if already at end. */
|
||
|
public void next();
|
||
|
|
||
|
/** @return The number of elements in the list. */
|
||
|
public int length();
|
||
|
|
||
|
/** @return The position of the current element. */
|
||
|
public int currPos();
|
||
|
|
||
|
/** Set current position.
|
||
|
@param pos The position to make current. */
|
||
|
public void moveToPos(int pos);
|
||
|
|
||
|
/** @return The current element. */
|
||
|
public T getValue();
|
||
|
|
||
|
/** @return True if k is in the list L, false otherwise */
|
||
|
public static boolean find(List<Integer> L, int k) {
|
||
|
for (L.moveToStart(); L.currPos() < L.length(); L.next()) {
|
||
|
if (k == L.getValue()) return true; // Found k
|
||
|
}
|
||
|
return false; // k not found
|
||
|
}
|
||
|
}
|