Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public ListItem<T> listsInList(ListItem<ListItem<T>> lsts) throws IllegalArgumentException
  2. {
  3. if (lsts == null)
  4. {
  5. throw new IllegalArgumentException("listsInList: The list must not be null");
  6. }
  7. else if (lsts.next == null)
  8. {
  9. // only one list in our list of lists -> return the key
  10. return lsts.key;
  11. }
  12. else
  13. {
  14. // check if our first list has only one element
  15. if (lsts.key.next == null)
  16. {
  17. // yes : start recursion with the first element of the next list
  18. lsts.key.next = listInListRec(lsts.next, lsts.next.key);
  19. }
  20. else
  21. {
  22. // no : start recursion with the second element of the first list
  23. lsts.key.next = listInListRec(lsts, lsts.key.next);
  24. }
  25. return lsts.key;
  26. }
  27.  
  28. }
  29.  
  30. /**
  31. * Hilfsmethode f眉r {@link Aufgabe_1.A.A#listsInList(data.ListItem)}
  32. *
  33. * @param remainingLists
  34. * @param currentItem
  35. * @return the next ListItem
  36. */
  37. private ListItem<T> listInListRec(ListItem<ListItem<T>> remainingLists, ListItem<T> currentItem)
  38. {
  39. if (remainingLists.next == null && currentItem.next == null)
  40. {
  41. return currentItem;
  42. }
  43. else if (currentItem.next == null)
  44. {
  45. currentItem.next = listInListRec(remainingLists.next, remainingLists.next.key);
  46. return currentItem;
  47. }
  48. else
  49. {
  50. currentItem.next = listInListRec(remainingLists, currentItem.next);
  51. return currentItem;
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement