Worked example 1
A music streaming service uses a playlist feature. Users can add a song to the end of the playlist, remove the currently playing song from the start, and see which song is next. Describe this playlist feature as an Abstract Data Type, specifying the data and the necessary operations.
Show solution outline
The playlist can be described as a Queue ADT.
Data: A collection of songs, where each song has a title and artist. The collection is ordered based on insertion time. [1 mark]
Operations:
- ENQUEUE(song): Adds a new song to the rear (end) of the queue/playlist. [1 mark]
- DEQUEUE(): Removes the song from the front of the queue/playlist (the one that has been there the longest). [1 mark]
- PEEK() or FRONT(): Returns the song at the front of the queue without removing it. [1 mark]
- isEmpty(): Returns TRUE if the queue/playlist contains no songs, otherwise FALSE. [1 mark]
(Note: The description correctly identifies the ADT and its operations without mentioning arrays or linked lists).