fishking00 2015-10-23 01:33 采纳率: 50%
浏览 1650

使用vc++6.0编单链表一直报各种错,小白真心求解

/list.h/
#include

template
class TLinkList;

template
class TNode
{private:
T data; //数据
TNode *next;//指向下一个节点的指针
public:
friend class TLinkList;//申请是链表类的友元类
TNode(T data=0,TNode *q=NULL);
~TNode(void);
};

template
class TLinkList
{private:
TNode *m_first;//链表头指针
public:
TLinkList();
void Input();//输入函数,即数据初始化
bool Insert(int i,T e);//插入函数
bool Delete(int i,T &e);//删除函数
int Search(T e);//查找函数
bool GetData(int i,T &e);//元素获取函数
bool SetData(int i,T e);//元素设置函数
void Traverse(void (*visit)(T e));//遍历输出
void makeEmpty();//delete all elements
~TLinkList();
};

template
TLinkList::TLinkList()
{m_first=new TNode;}

template
TLinkList::~TLinkList()
{makeEmpty();}

template
void TLinkList::Input()//input function
{TNode *current=m_first->next;
int x,n;
cout<<"input the length of the list"< cin>>n;
for(int i=1;i {TNode *p=new TNode;
cout<<"input the data"< cin>>x;
current->data=x;
current->next=p;
current=p;
}
current->next=NULL;
}

template//insert an element into the list
bool TLinkList::Insert(int i,T e)
{TNode *newNode=new TNode(e);
if(newNode==NULL) {cout<<"error"< else{TNode *current=m_first->next;
for(int k=1;k {if(current==NULL)break;
else current=current->next;
}
if(current==NULL){cout<<"error"< else{newNode->next=current->next;
current->next=newNode;}
return true;
}

template//delete an element from the list
bool TLinkList::Delete(int i,T &e)
{ TNode *current=m_first->next,*deletepoint;
for(int k=1;k {if(current==NULL)break;
else current=current->next;
}
if(current==NULL){cout<<"error"< else{deletepoint=current->next;
current->next=deletepoint->x;}
e=deletepoint->data;
delete deletepoint;
return true;
}

template//search
int TLinkList::Search(T e)
{TNode *current=m_first->next;
int count=0;
while(current!=NULL)
{if(current->data==e)break;
else current=current->next;
count++;
}
if(current->next==NULL){count=0;}
return count;
}

template//get
bool TLinkList::GetData(int i,T &e)
{TNode *current=m_first->next;
for(int k=1;k {current=current->next;
if(current==NULL){cout<<"error"<<endl;return false}
}
e=current.data;
return true;
}

template//set
bool TLinkList::SetData(int i,T e)
{TNode *current=m_first->next;
for(int k=1;k {current=current->next;
if(current==NULL){cout<<"error"< }
current->data=e;
return true;
}

template//makeEmpty
void TLinkList::makeEmpty()
{TNode *current;
while(m_first->next!=NULL)
{current=m_first->next;
first->next=current->next;
delete current;}
}

template//遍历
void TLinkList::Traverse(void (*visit)(T e))
{TNode *current=m_first->next,*p;
while(current->next!=NULL)
{
p=current->next;
current=p->next;
visit(p->data);
}
}

/main.cpp/
#include
#include"list.h"
#include"stdlib.h"
using namespace std;

template
void Output(T x)
{cout<<"|"<<x<<"|"<<" ";}

void main()
{int i,e;
char x,y;
TLinkList A;
while(x!=0){
cout<<" 请输入一个数字: "< cout cout cout cout cout cout cout cout cout cout cout cout cout cout cout cout cout cin>>x;
switch(x)
{case '1':A.Input();cout<<"按任意键返回菜单"< cin>>y;
system("cls");break;

case '2':cout<<"输入删除的位置"< cin>>i;

A.Delete(i,e);cout<<"按任意键返回菜单"< cin>>y;
system("cls");break;

case '3':cout<<"输入插入的位置"< cin>>i;

cout<<"输入插入的数字"< cin>>e;
A.Insert(i,e);
cout<<"按任意键返回菜单"< cin>>y;
system("cls");
break;

case '4':
A.Traverse(Output);cout<<"按任意键返回菜单"< cin>>y;system("cls");break;
break;

case '5':cout<<"输入需要查找的数字"< cin>>e;
if(A.Search(e)) cout<<"这个数字位于第"< else cout cout cin>>y;
system("cls");break;

case '6':cout<<"输入需要获取的位置"< cin>>i;
if(A.GetData(i,e)) cout<<"第"< cout cin>>y;
system("cls");break;

case '7':cout<<"输入需要设置的位置"< cin>>i;
cout<<"输入需要设置的数字"< cin>>e;
A.SetData(i,e);
cout<<"按任意键返回菜单"< cin>>y;
system("cls");break;

case '0':break;

default:cout<<"请输入正确的数字"< cin>>y;
system("cls");break;
}
}
}

软件就报几种错
1.编辑通过,组建的时候写unresolved external symbol _main
2.说我的system没有定义(不过已经写了头文件)
3.D:\keshe\single list\main.cpp(17) : error C2872: 'cout' : ambiguous symbol

希望大家可以解惑..

  • 写回答

1条回答 默认 最新

  • threenewbee 2015-10-23 01:45
    关注
     #include<iostream.h>
    ->
    #include<iostream>
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?