| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:[求助]链表问题
只看楼主 加入收藏
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
 问题点数:0 回复次数:4 
[求助]链表问题

这是我写的,但有些错误不知怎么改,望大家帮我一下!谢谢!
#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)

搜索更多相关主题的帖子: 链表 
2006-11-17 20:10
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 
Node node(name,no);
rear->next=node;
你可看清楚了,next可是Node*类型啊!

[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-11-17 20:45
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
得分:0 

哦,知道了,谢谢了!

2006-11-17 22:05
clzdl
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2006-11-17
收藏
得分:0 

还有问题是,我这么输出数据为什么不行?

2006-11-18 08:15
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
得分:0 

是啊 ,版主帮忙看一下啊,还有这么用if(strcmp(m_next->Name,item)==0)行吗?

2006-11-18 08:18
快速回复:[求助]链表问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023959 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved