写完这个代码后 不能运行,也知道public函数的问题,在cpp文件里没有成功调用,然后makefile文件也出现错误。哪位可以帮我修改一下呢 或者哪里不对呢?真的找不到问题了谁可以来指点一下我,不胜感激!!
main.cpp
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#include"LinkList.cpp"
int main(int argc, char** argv) {
int r[5]={1,2,3,4,5},i,x;
LinkList <int> L(r,5);
cout<<"当前线性表的数据为:" ;
L.PrintList();
try
{
L.Insert(2,8);
cout<<"执行插入操作后的数据为" ;
L.PrintList();
}
catch (char *str)
{
cout<"当前单链表的长度为:"<Length()<try
{
cout<<"请输入要删除第几个元素:";
cin>>i;
x=L.Delete(i);
cout<<"删除的元素值是"<",执行删除操作后数据为:";
L.PrintList();
}
catch (char *str)
{
cout<0;
}
#ifndef LinkList_H
#define LinkList_H
#include
using namespace std;
template <typename T>
struct Node
{
T data;
Node *next;
};
template <typename T>
class LinkList
{
public:
LinkList();
LinkList(T a[], int n);
~LinkList();
int Length();
void Insert(int i, T x);
T Delete(int i);
void PrintList();
private:
Node *first;
};
#endif
#include"LinkList.h"
template <class T>
LinkList<T>::LinkList(T a[], int n)
{
first=new Node;
first->next = 0;
for(int i=0;i<=n;i++)
{
Node*s=0;
s=new Node;
s->next =first->next ;
first->next =s;
}
}//建立单链表
template <class T>
int LinkList<T>::Length()
{
Node*p=first->next ;
int count=0;
while (p!=0)
{
p=p->next ;
count++;
}
return count;
}//求长度
template <class T>
void LinkList<T>::Insert(int i,T x)
{
Node*p=first, *s=0;
int count=0;
while (p!=0&&count-1)
{
p=p->next ;
count++;
}
if(p==0) throw "插入位置错误";
else
{
s=new Node;
s->next ;
p->next =s;
}
}//插入操作
template <class T>
T LinkList<T>::Delete(int i)
{
T x;
Node *p=first,*q=0;
int count=0;
while(p!=0&&count-1)
{
p=p->next ;
count++;
}
if (p==0||p->next ==0)
throw "删除位置错误";
else
{
q=p->next ;
x=q->data;
p->next =q->next;
delete q;
return x;
}
} //删除操作
运行碰到的第一个错误是什么?