#include<iostream>
using namespace std;
struct node
{
node()
{
next=NULL;
}
/**
node(int *y,char *s,int x,node *link)
{
for(int a=0,b=0;y[a]!=-1;a++,b++)
music[b]=y[a];
name=s;
i=x;
next=link;
}
/**/
int music[10];
char name[10]; // 改过
int i;
node *next;
};
class LinkList
{
public:
LinkList()
{
first=NULL;
n=0;
}
void Insert(int pos,int m[],char str[]);
void Setup();
void Display();
void Play(node *p);
int length()
{
return n;
}
node* SetPos(int pos);
protected:
node *first;
int n;
};
node* LinkList::SetPos(int pos)
{
node *q=first;
for(int i=0;i<pos;i++)
q=q->next;
return q;
}
void LinkList::Setup()
{
node *q,*p;
int xiaomifeng[]={1,2,3,4,5,-1};
// q=new node(xiaomifeng,"小蜜蜂",1,NULL);
q=new node;
q->i=1;
memcpy(q->music,xiaomifeng,sizeof(q->music));
strcpy(q->name,"小蜜蜂");
q->next=first;
first=q;
int yujian[]={5,4,3,2,1,-1};
p=new node;
p->i=2;
::memcpy(p->music,yujian,sizeof(p->music));
::strcpy(p->name,"遇见");
p->next=q->next;
q->next=p;
// p=new node(yujian,"遇见",2,NULL);
// p->next=q->next;
// q->next=p;
n+=2;
}
void LinkList::Play(node *p)
{
node *q=p;
int i=0;
while(q->music[i]!=-1)
{
cout<<q->music[i];
i++;
}
cout<<endl;
}
void LinkList::Insert(int pos,int m[],char str[])
{
node *p,*q;
p=new node;
p->i=pos+1;
::memcpy(p->music,m,sizeof(p->music));
::strcpy(p->name,str);
if(pos>0)
{
q=SetPos(pos-1);
p->next=q->next;
q->next=p;
}
else
{
p->next=first;
first=p;
}
n++;
}
void LinkList::Display()
{
node *m=first;
int j;
cout<<"歌曲列表\n";
for(int a=1;a<=n;a++)
{
cout<<a<<'.'<<m->name<<endl;
m=m->next;
}
cout<<"按-1可以退到上一级别菜单\n";
cout<<"请选择:";
cin>>j;
while(j>0)
{
j=j-1;
node *z=SetPos(j);
Play(z);
cout<<"歌曲列表\n";
node *f=first;
for(int a=1;a<=n;a++)
{
cout<<a<<'.'<<f->name<<endl;
f=f->next;
}
cout<<"按-1可以退到上一级别菜单\n";
cout<<"请选择:";
cin>>j;
}
}
int main()
{
LinkList nick;
int w,x,y,z=0;
int s[100];
char str[10];
nick.Setup();
cout<<"**********************************欢迎使用此软件********************************\n";
cout<<" 1.点播歌曲\n";
cout<<" 2.自己写歌\n";
cout<<" 3.退出系统\n\n\n";
cout<<" 请做出选择....:";
cin>>x;
while(x>0)
{
if(x==1)
nick.Display();
if(x==2)
{
cout<<"请输入这是第几首歌:";
cin>>w;
cout<<"请输入歌曲的音阶以-1结束:";
cin>>y;
while(y!=-1)
{
s[z]=y;
z++;
cin>>y;
}
s[++z]=-1;
cout<<"请输入歌名:";
cin>>str;
w=w-1;
nick.Insert(w,s,str);
}
if(x==3)
{
cout<<" 欢迎再次使用!\n";
break;
}
cout<<"**********************************欢迎使用此软件********************************\n";
cout<<" 1.点播歌曲\n";
cout<<" 2.自己写歌\n";
cout<<" 3.退出系统\n\n\n";
cout<<" 请做出选择....:";
cin>>x;
}
return 0;
}
程序编译没错误...运行时当写入数组进行输出时..出现乱码...请指教