The information about a song should include:
Artist name
Title
Length
Number of likes
The data members for SongList should be a head pointer to a linear linked list of Song objects and the number of songs in the list. The songs should be organized by popularities with the most popular song as the first node in the list.
This ADT must have public member functions to perform the following:
Constructor - Construct an object and initialize the data members
Destructor - Release all dynamic memory and reset data members to their zero equivalent value
Add a new song
Edit the number of likes for a song
Display all songs in the list
Display all songs for an artist (in order of popularity)
Remove all songs with fewer than M likes, where M is sent in as an argument
The test program needs to first load the test data set from external file at the beginning of the program.
#include <bits/stdc++.h>
using namespace std;
class Node {
public:
int data;
Node* next;
};
void sortedInsert(Node** head_ref,
Node* new_node)
{
Node* current;
if (*head_ref == NULL
|| (*head_ref)->data
>= new_node->data) {
new_node->next = *head_ref;
*head_ref = new_node;
}
else {
current = *head_ref;
while (current->next != NULL
&& current->next->data
< new_node->data) {
current = current->next;
}
new_node->next = current->next;
current->next = new_node;
}
}
Node* newNode(int new_data)
{
Node* new_node = new Node();
new_node->data = new_data;
new_node->next = NULL;
return new_node;
}
void printList(Node* head)
{
Node* temp = head;
while (temp != NULL) {
cout << temp->data << " ";
temp = temp->next;
}
}
int main()
{
/* Start with the empty list */
Node* head = NULL;
Node* new_node = newNode(5);
sortedInsert(&head, new_node);
new_node = newNode(10);
sortedInsert(&head, new_node);
new_node = newNode(7);
sortedInsert(&head, new_node);
new_node = newNode(3);
sortedInsert(&head, new_node);
new_node = newNode(1);
sortedInsert(&head, new_node);
new_node = newNode(9);
sortedInsert(&head, new_node);
cout << "Created Linked List\n";
printList(head);
return 0;
}
Comments
Leave a comment