Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JAVA Q2.1 Ideate 6 Points Data Structure This question can be solved using a linked list. Each PlaylistNode has a reference to the next

In JAVA

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Q2.1 Ideate 6 Points Data Structure This question can be solved using a linked list. Each PlaylistNode has a reference to the next node in the chain. They also hold a piece of information on each song. In our case, the song's title is all we need. Write down the class definition for this data structure: public class PlaylistNode { // Declare instance variables Enter your answer here public PlaylistNode(T title) { Enter your answer here } public String getTitle() { Enter your answer here public void setTitle(t input) { Enter your answer here } public PlaylistNode getNext() { Enter your answer here } public void setNext (PlaylistNode nex ut) { Enter your answer here } } Q2.3 8 Points How can you reverse a simple 2-song playlist, given the first (head) node? Return the new head node. Input: Loving Is Easy" -> "Back Pocket" -> NU Return: PlaylistNode Back Pocket" public static PlaylistNode reverseTinyPlaylist(PlaylistNode head) { Enter your answer here } Q2.4 8 Points Now, can you use this approach to reverse the entire playlist? Again, make sure you return the new head of the list. Try to do this without the use of a stack or any extra memory besides the nodes given. No extra nodes need to be created; reverse the list in place. Think of an algorithm and try it out on our examples from before. Example 1 Input: Tokyo Drifting" -> "Highest In The Room" -> "Que Calor" -> NULL Output: Que Calor -> Highest In The Room -> Tokyo Drifting" -> NULL Example 2 Input: Loving Is Easy" -> "Back Pocket" -> NULL Output: Back Pocket" -> "Loving Is Easy -> NULL Code up the algorithm. Vocalize your decisions with your partner, and explain what you are writing. public static PlaylistNode reversePlaylist(PlaylistNode head) { Enter your answer here } Q2.4 8 Points Now, can you use this approach to reverse the entire playlist? Again, make sure you return the new head of the list. Try to do this without the use of a stack or any extra memory besides the nodes given. No extra nodes need to be created; reverse the list in place. Think of an algorithm and try it out on our examples from before. Example 1 Input: Tokyo Drifting" -> "Highest In The Room" -> "Que Calor" -> NULL Output: Que Calor -> Highest In The Room -> Tokyo Drifting" -> NULL Example 2 Input: Loving Is Easy" -> "Back Pocket" -> NULL Output: Back Pocket" -> "Loving Is Easy -> NULL Code up the algorithm. Vocalize your decisions with your partner, and explain what you are writing. public static PlaylistNode reversePlaylist(PlaylistNode head) { Enter your answer here }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions