0% found this document useful (0 votes)
10 views9 pages

Code Output Assign5

The document outlines a C++ program that implements a simple music playlist using a circular linked list. It allows users to add, delete, and navigate through songs, displaying the current playlist in a loop. The program includes a main function that facilitates user interaction through various commands.

Uploaded by

krishnasawale237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

Code Output Assign5

The document outlines a C++ program that implements a simple music playlist using a circular linked list. It allows users to add, delete, and navigate through songs, displaying the current playlist in a loop. The program includes a main function that facilitates user interaction through various commands.

Uploaded by

krishnasawale237
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY

PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

Title: Exp - 5
Create a C++ program using a circular linked list to implement a
simple music playlist. Each song should have a title and duration.
Problem
Statement The program should support adding a song, deleting a song,
moving to next song and displaying the current playlist in a loop

CODE :

/*
Name : Krishna Sawale
Roll No: 22367
Division: 7
Batch: G7
Problem Statement:
Create a C++ program using a circular linked list to implement a
simple music playlist.
Each song should have a title and duration. The program should
support adding a song,
deleting a song, moving to next song, moving to previous song, and
displaying the
current playlist in a loop.
*/

#include <iostream>
#include <string>
using namespace std;

// Class representing a Song node

DSA_LAB_2025-26: Program input output 1


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

class Song {
public:
string title;
float duration;
Song* next; // Pointer to next song
Song* prev; // Pointer to previous song

Song(string til, float dur) {


title = til;
duration = dur;
next = NULL;
prev = NULL;
}
};

// Class representing the Playlist (Circular Doubly Linked List)


class Playlist {
private:
Song* head; // First song in the playlist
Song* tail; // Last song in the playlist
Song* current; // Currently playing song

public:
Playlist() {
head = NULL;
tail = NULL;
current = NULL;
}

DSA_LAB_2025-26: Program input output 2


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: Submission date:

// Add song
void addsong(string title, float duration) {
Song* newSong = new Song(title, duration);
if (head == NULL) {
head = newSong;
head->next = head;
head->prev = head;
tail = newSong;
current = head;
} else {
tail->next = newSong;
newSong->prev = tail;
newSong->next = head;
head->prev = newSong;
tail = newSong;
}
cout << "Added song: " << title << endl;
}

// Delete song
void deletesong(string title) {
if (head == NULL) {
cout << "Playlist is empty. Cannot delete song." << endl;
return;
}

Song* currentSong = head;


do {
if (currentSong->title == title) {

DSA_LAB_2025-26: Program input output 3


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

if (head == tail) {
delete currentSong;
head = tail = current = NULL;
} else {
currentSong->prev->next = currentSong->next;
currentSong->next->prev = currentSong->prev;
if (currentSong == head) head = currentSong->next;
if (currentSong == tail) tail = currentSong->prev;
if (current == currentSong) current = currentSong->next;
delete currentSong;
}
cout << "Deleted song: " << title << endl;
return;
}
currentSong = currentSong->next;
} while (currentSong != head);

cout << "Song not found: " << title << endl;
}

// Play next song


void nextsong() {
if (head == NULL) {
cout << "Playlist is empty." << endl;
return;
}
current = current->next;
cout << "Now playing: " << current->title << " (" << current-
>duration << " mins)" << endl;

DSA_LAB_2025-26: Program input output 4


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

// Play previous song


void prevsong() {
if (head == NULL) {
cout << "Playlist is empty." << endl;
return;
}
current = current->prev;
cout << "Now playing: " << current->title << " (" << current-
>duration << " mins)" << endl;
}

// Display playlist
void display() {
if (head == NULL) {
cout << "Playlist is empty." << endl;
return;
}
Song* temp = head;
cout << "Playlist:" << endl;
do {
cout << temp->title << " (" << temp->duration << " mins)" <<
endl;
temp = temp->next;
} while (temp != head);
}
};

DSA_LAB_2025-26: Program input output 5


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

// Main function
int main() {
Playlist myPlaylist;
cout << "Choose the command:\n"
<< "1. Add a song\n"
<< "2. Delete a song\n"
<< "3. Play next song\n"
<< "4. Play previous song\n"
<< "5. Display playlist\n"
<< "6. Exit" << endl;

int command, ch;


string title;
float duration;

do {
cout << "Enter command: ";
cin >> command;
switch (command) {
case 1:
cout << "Enter song title: ";
cin >> title;
cout << "Enter song duration (in mins): ";
cin >> duration;
[Link](title, duration);
break;
case 2:
cout << "Enter song title to delete: ";
cin >> title;

DSA_LAB_2025-26: Program input output 6


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

[Link](title);
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
[Link]();
break;
case 6:
cout << "Exiting..." << endl;
return 0;
default:
cout << "Invalid command." << endl;
}
cout << "Press 1 to continue and 0 to exit: ";
cin >> ch;
} while (ch != 0);

return 0;
}

PS C:\Users\akash\Desktop\CODES\DATA_STRUCTURE\sorting>
./[Link]

DSA_LAB_2025-26: Program input output 7


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: 22367 Submission date:

OUTPUT :

Choose the command:


1. Add a song
2. Delete a song
3. Play next song
4. Play previous song
5. Display playlist
6. Exit
Enter command: 1
Enter song title: a
Enter song duration (in mins): 3
Added song: a
Press 1 to continue and 0 to exit: 1
Enter command: 1
Enter song title: b
Enter song duration (in mins): 4
Added song: b
Press 1 to continue and 0 to exit: 1
Enter command: 1
Enter song title: c
Enter song duration (in mins): 5
Added song: c
Press 1 to continue and 0 to exit: 1
Enter command: 3
Now playing: b (4 mins)
Press 1 to continue and 0 to exit: 1

DSA_LAB_2025-26: Program input output 8


SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY
PUNE - 411043
Department of Electronics & Telecommunication Engineering
ASSESMENT YEAR: 2025-2026 CLASS: SY
SUBJECT: DATA STRUCTURES AND ALGORITHMS
EXPT No: LAB Ref: SY/2025-26/ Starting date:
Roll No: Submission date:

Enter command: 5
Playlist:
a (3 mins)
b (4 mins)
c (5 mins)
Press 1 to continue and 0 to exit: 1
Enter command: 2
Enter song title to delete: b
Deleted song: b
Press 1 to continue and 0 to exit: 1
Enter command: 5
Playlist:
a (3 mins)
c (5 mins)

DSA_LAB_2025-26: Program input output 9

You might also like