这是我写的,但有些错误不知怎么改,望大家帮我一下!谢谢!
#include <iostream>
#include<cstring>
using namespace std;
class Node
{
public:
Node *next;
char Name[10];
char No[10];
class LinkedList;
public:
Node( char name[], char no[]):next(NULL)
{strcpy(Name,name);
strcpy(No,no);
}
};
class LinkedList
{
public :
Node *front,*rear;
int pos;
int size ;
public:
LinkedList():front(0),rear(0),size(0),pos(0){}
void Add_rear(char name[],char no[])
{ Node node(name,no);
rear->next=node;
rear=node;
size++;
}
void Add_front(char name[],char no[])
{ Node node(name,no);
node.next=front->next;
front=node;
size++;
}
void Add_at(int n,char name[],char no[])
{ Node *m_next;
m_next=front;
for(int i=0;i<n-1;i++)
m_next=m_next->next;
Node node(name,no);
node.next=m_next;
m_next=node;
size++;
}
void delete_front()
{
if(size==0)
{ cout<<"链表空!"<<endl;
exit(1);
}
front=front->next;
size--;
}
void delete_at(int n)
{
if(size==0)
{cout<<"链表空 !"<<endl;
exit(1);
}
Node *m_next;
m_next=front;
for(int i=0;i<n-1;i++)
m_next=m_next->next;
m_next=m_next->next;
size--;
}
void find(int index)
{ Node *m_front;
if((index<0)||(index>size))
{cout<<"不存在此数据!"<<endl;
exit(1);
}
for(int i=0;i<index-1;i++)
m_front=m_front->next;
cout<<"姓名是:"<<m_front->Name<<endl<<"电话是:"<<m_front->No<<endl;
}
void find (char item[])
{ Node *m_next ;
m_next=front;
for(int i=0;i<=size;i++)
{ if((strcmp(m_next->Name,item)==0))
cout<<"你要找的电话是:"<<m_next->No<<endl;
m_next=m_next->next;
}
}
};
void main()
{ int ch,exit=0;
char name[10],no[10];
LinkedList list ;
cout<<"请选择:1 添加 2 删除 3 查找 4 显示所有的记录"<<endl;
cin>>ch;
while (!exit)
{
switch(ch)
{
case 1:
cout<<"请输入要添加人的姓名:"<<endl;
cin>>name;
cout<<"请输入要添加人的电话:"<<endl;
cin>>no;
cout<<"请选择添加方式: 1 表头添加 2表尾添加 特定位置添加"<<endl;
int ch1;
cin>>ch1;
switch(ch1)
{
case 1:
list.Add_front(name,no);
break;
case 2:
list.Add_rear(name,no);
break;
case 3:int m;
cout<<"请输入要添加的位置:"<<endl;
cin>>m;
list.Add_at(m,name,no);
break;
}
cout<<"退出请选:1"<<endl;
cin>>exit;
break;
case 2:int ch2;
cout<<"请选择删除的方式:1 表头删除 2 特定位置删除"<<endl;
cin>>ch2;
switch(ch2)
{
case 1: list.delete_front();
break;
case 2: int m;
cout<<"请输入要删除数据的位置"<<endl;
cin>>m;
list.delete_at(m);
break;
}
cout<<"退出请选:1"<<endl;
cin>>exit;
break;
case 3:int ch3;
cout<<"请选择要查找的方式: 1 姓名查找 2 特定位置查找 "<<endl;
cin>>ch3;
switch(ch3)
{ case 1: cout<<"请输入姓名"<<endl;
cin>>name;
list.find(name);
break;
case 2: int m;
cout<<"请输入要查找的数据的位置"<<endl;
cin>>m;
list.find(m);
break;
}
cout<<"退出请选:1"<<endl;
cin>>exit;
break;
case 4:Node *m_next;
m_next=list.front;
cout<<"所有的记录:"<<endl;
for(int i=0;i<list.size;i++)
{cout<<m_next->Name<<endl<<m_next->No<<endl;
m_next=m_next->next;
}
cout<<"退出请输入:1"<<endl;
cin>>exit;
break;
}
}
}
错误调试:
------------------Configuration: 11 - Win32 Debug--------------------
Compiling...
11.cpp
D:\学习文件\CL\zuoye\11\11.cpp(30) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Node' (or there is no acceptable conversion)
D:\学习文件\CL\zuoye\11\11.cpp(31) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Node' (or there is no acceptable conversion)
D:\学习文件\CL\zuoye\11\11.cpp(37) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Node' (or there is no acceptable conversion)
D:\学习文件\CL\zuoye\11\11.cpp(47) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class Node' (or there is no acceptable conversion)
执行 cl.exe 时出错.
11.obj - 1 error(s), 0 warning(s)