You are on page 1of 5

#include <stdio.

h>
#include <conio.h>
#include <iostream>
#include <fstream>

using namespace std;

struct BaiHat
{
char tenBH[51];
char tenTG[41];
char tenCS[41];
int thoiLuong;
};

struct Node
{
BaiHat info;
Node* next;
};

struct SList
{
Node *head;
Node *tail;
};

SList dsbh;

void addHead(SList &sl, Node* p)


{
if(p == NULL)
return;
else
{
if (sl.head == NULL)
sl.head = sl.tail = p;
else
{
p -> next = sl.head;
sl.head = p;
}
}
}

void initSList(SList &sl)


{
sl.head = NULL;
sl.tail = NULL;
}

int isEmpty(SList sl)


{
if(sl.head == NULL)
{
return 1;
}
else
{
return 0;
}
}

void showList(SList sl, int n)


{
if (isEmpty(sl) == 1)
{
printf("Danh sach rong");
return;
}
else
{
Node* p = sl.head;
printf("\n");
printf("\n");
for (int i = 1; i <= n; i++)
{
if (p == NULL)
{
printf("Rong");
return;
}

printf("\nTenBH: %s", p ->info.tenBH);


printf("\nTenCS: %s", p ->info.tenCS);
printf("\nTenTG: %s", p ->info.tenTG);
printf("\nThoi Luong: %d\n", p ->info.thoiLuong);

p = p->next;
}
}
}

void docList(SList &dsbh, char* filename, int &n)


{
ifstream in;
in.open(filename);
if(in)
{
in>>n;
for(int i=1; i<=n; i++)
{
Node*p = new Node;
in >> p->info.tenBH;
in >> p->info.tenCS;
in >> p->info.tenTG;
in >> p->info.thoiLuong;

addHead(dsbh,p); // th�m b�i h�t node p v�o ds


}
}
in.close();
}

//void addHeadSList(SList &BaiHat, Node* tenBH)


//{
//
//}

/*void XoaKhoiDS(SList& sl)


{
int x;
Node* node = sl.head;
while (node != NULL)
{
RemoveHead(l, x);
node = sl.head;
}
sl.tail = NULL;
}
*/

/*int Search_x(SList& sl, int &x){


node *P=sl; // Khai b�o con tr? P tr? t?i sl
int i=1;
while(P!=NULL && P->Data!=x){
i++;
P=P->Next;
}
if(P!=NULL) //N?u danh s�ch kh�c r?ng th� tr? v? i
return i;
else // N?u danh s�ch r?ng th� tr? v? 0;
return 0;
}
*/

/Them vao dau danh sach


/*void addDau(SList &sl, int &x){
node *P = Node(P,x);
if(sl == NULL)
sl=P;
else{
P->Next=sl;
sl=P;
}
}
//them vao cuoi danh sach
void addCuoi(SList & sl, int &x){
Node *P = sl;
Node * temp =Node(temp,x);

if(sl==NULL)
sl=temp;
else{
while(P->Next!=NULL){
P=P->Next;
}
P->Next=temp;
}
}
*/
void menu()
{
printf("--------------------------------------
MENU--------------------------------------\n");
printf("0. Thoat chuong chuong trinh\n");
printf("1. �?c danh s�ch list nh?c t? file d?nh d?ng txt.\n");
printf("2. In danh s�ch c�c b�i h�t ra m�n h�nh.\n");
printf("3. �? nghe h?t t?t c? b�i h�t trong playlist ph?i c?n bao nhi�u th?i
gian.\n");
printf("4. Th�m m?t b�i nh?c m?i v�o d?u playlist/cu?i playlist.\n");
printf("5. X�a m?t b�i nh?c kh?i danh s�ch.\n");
printf("6. Ki?m tra xem bai hat c� t�n X c� trong playlist kh�ng ?.\n");
printf("7. Sap x?p c�c b�i hat trong playlist theo th? t? t? di?n c?a t�n b�i
h�t.\n");
printf("8. S?p x?p c�c b�i h�t th? t? gi?m d?n c?a t�n ca si.\n");
printf("9. �ua m?t b�i h�t trong playlist l�n d?u.\n");

printf("---------------------------------------------------------------------------
-----\n");
}
int main()
{
int n;
int luachon;

do
{
menu();
printf("Chon yeu cau :");
scanf_s("%d", &luachon);

switch (luachon)
{
case 0:
break;
case 1:
{
int n;
char* filename = (char*)"E:\input.txt";
printf("%s", filename);
initSList(dsbh);
docList(dsbh, filename, n);
showList(dsbh, n);
break;
}
case 2:
{
break;
}
case 3:
{

return 0;

break;
}
case 4:
{

printf("");
break;
}
case 5:
{
printf("");

break;
}
case 6:
{
printf("");

break;
}
case 7:
{
printf("");

break;
}
case 8:
{
int x;
printf("\n ");

break;
}
case 9:
{
printf("\n ");

break;
}
default:
printf("Yeu cau vua nhap khong kha dung !");
break;
}
} while (luachon != 0);
getch();
}

You might also like