Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ListItem<T> listsInList(ListItem<ListItem<T>> lsts) throws IllegalArgumentException
- {
- if (lsts == null)
- {
- throw new IllegalArgumentException("listsInList: The list must not be null");
- }
- else if (lsts.next == null)
- {
- // only one list in our list of lists -> return the key
- return lsts.key;
- }
- else
- {
- // check if our first list has only one element
- if (lsts.key.next == null)
- {
- // yes : start recursion with the first element of the next list
- lsts.key.next = listInListRec(lsts.next, lsts.next.key);
- }
- else
- {
- // no : start recursion with the second element of the first list
- lsts.key.next = listInListRec(lsts, lsts.key.next);
- }
- return lsts.key;
- }
- }
- /**
- * Hilfsmethode f眉r {@link Aufgabe_1.A.A#listsInList(data.ListItem)}
- *
- * @param remainingLists
- * @param currentItem
- * @return the next ListItem
- */
- private ListItem<T> listInListRec(ListItem<ListItem<T>> remainingLists, ListItem<T> currentItem)
- {
- if (remainingLists.next == null && currentItem.next == null)
- {
- return currentItem;
- }
- else if (currentItem.next == null)
- {
- currentItem.next = listInListRec(remainingLists.next, remainingLists.next.key);
- return currentItem;
- }
- else
- {
- currentItem.next = listInListRec(remainingLists, currentItem.next);
- return currentItem;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement