Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

why i have error in this code in Track: class Node { Track data; Node prev; Node next; public Node ( Track data ) {

why i have error in this code in "Track":
class Node {
Track data;
Node prev;
Node next;
public Node(Track data){
this.data = data;
}
}
class DoublyCircularLinkedList {
Node head;
Node tail;
// Add track to the end of the playlist
public void addTrack(Track track){
Node newNode = new Node(track);
if (head == null){
head = newNode;
tail = newNode;
newNode.next = newNode;
newNode.prev = newNode;
} else {
tail.next = newNode;
newNode.prev = tail;
newNode.next = head;
head.prev = newNode;
tail = newNode;
}
}
// Remove track from the playlist
public void removeTrack(Track track){
if (head == null){
return;
}
Node current = head;
do {
if (current.data.equals(track)){
if (current == head){
head = current.next;
}
if (current == tail){
tail = current.prev;
}
current.prev.next = current.next;
current.next.prev = current.prev;
return;
}
current = current.next;
} while (current != head);
}
// Skip to the next track
public void skip(){
if (head != null){
head = head.next;
}
}
// Get the current track
public Track getCurrentTrack(){
if (head != null){
return head.data;
}
return null;
}
// Display the playlist
public void displayPlaylist(){
if (head == null){
System.out.println("Playlist is empty.");
return;
}
Node current = head;
do {
System.out.println(current.data);
current = current.next;
} while (current != head);
}
}
how to import Track class?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions