找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 434|回复: 4

[求助]链表问题

[复制链接]
发表于 2009-11-4 01:13:35 | 显示全部楼层 |阅读模式 IP:江苏扬州
这是我写的,但有些错误不知怎么改,望大家帮我一下!谢谢!
#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)
发表于 2009-11-4 01:13:36 | 显示全部楼层 IP:江苏扬州
Node node(name,no);
rear->next=node;
你可看清楚了,next可是Node*类型啊!
回复

使用道具 举报

发表于 2009-11-4 01:13:37 | 显示全部楼层 IP:江苏扬州
哦,知道了,谢谢了!
回复

使用道具 举报

发表于 2009-11-4 01:13:38 | 显示全部楼层 IP:江苏扬州
还有问题是,我这么输出数据为什么不行?
回复

使用道具 举报

发表于 2009-11-4 01:13:40 | 显示全部楼层 IP:江苏扬州
是啊 ,版主帮忙看一下啊,还有这么用if(strcmp(m_next->Name,item)==0)行吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 01:17 , Processed in 0.124443 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表