DSA Lab Assignment # 2 (FA23-BSE-126)
DSA Lab Assignment # 2 (FA23-BSE-126)
Reg no FA23-BSE-126
public Playlist() {
this.head = null;
currPlaying = null;
}
// to add a song
public void addSong(String name , String artist){
Node newNode = new Node(name , artist);
if(head == null){
head = newNode;
currPlaying = head;
System.out.println("Song "+name+" added at start successfully.." );
return;
}
Node curr = head;
while(curr.next != null){
curr = curr.next;
}
curr.next = newNode;
newNode.prev = curr;
System.out.println("Song "+name+" added at last successfully.." );
}
if(head.next == null){
if (Objects.equals(head.songTitle, title)) {
System.out.println("The only song in the list "+head.songTitle+" is
removed..");
head = null;
currPlaying = null;
return;
}
System.out.println("not found at first position...");
return;
}
if(Objects.equals(head.songTitle,title)){
System.out.println("The first song "+head.songTitle+" in the list is
removed..");
head = head.next;
head.prev = null;
currPlaying = currPlaying.next;
return;
}
if(currPlaying == null){
System.out.println("List is empty");
}else if(currPlaying.next == null){
System.out.println(currPlaying.songTitle+" is Last song..");
return;
}
currPlaying= currPlaying.next;
System.out.println(currPlaying.songTitle + " is playing currently..");
}
}
}
Output: