You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.9 KiB

6 years ago
  1. // The SongList class that represents a circular linked list of Song nodes
  2. // Your name here
  3. public class SongList
  4. {
  5. // instance variables
  6. private Song m_last;
  7. private int m_numElements;
  8. // constructor
  9. // Do not make any changes to this method!
  10. public SongList()
  11. {
  12. m_last = null;
  13. m_numElements = 0;
  14. }
  15. // check whether the list is empty
  16. // Do not make any changes to this method!
  17. boolean isEmpty()
  18. {
  19. if (m_last == null)
  20. return true;
  21. else
  22. return false;
  23. }
  24. // return the size of the list (# of Song nodes)
  25. // Do not make any changes to this method!
  26. public int size()
  27. {
  28. return m_numElements;
  29. }
  30. // add a new Song to the circular linked list with the given artist and
  31. // title, keeping the list sorted by *song title*.
  32. public void add(String artist, String title)
  33. {
  34. // TODO: implement this method
  35. }
  36. // remove a Song associated with the given artist and title from the list,
  37. // keeping the list sorted by *song title*.
  38. public boolean remove(String artist, String title)
  39. {
  40. // TODO: implement this method
  41. }
  42. // build and return a circular linked list that contains all songs from the
  43. // given artist
  44. public SongList buildList(String artist)
  45. {
  46. // TODO: implement this method
  47. }
  48. // return a string representation of the list
  49. // Do not make any changes to this method!
  50. public String toString()
  51. {
  52. String listContent = "";
  53. Song current = m_last;
  54. if (m_last != null)
  55. do
  56. {
  57. current = current.getLink();
  58. listContent += " [" + current.getArtist() + " - " + current.getTitle() + "]\n";
  59. } while (current != m_last);
  60. return listContent;
  61. }
  62. }