错误如下
错误 LNK1120 8 个无法解析的外部命令 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\Debug\ConsoleApplication2.exe 1
错误 LNK2019 无法解析的外部符号 "public: bool __thiscall CriList::empty(void)" (?empty@?$CriList@H@@QAE_NXZ),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: class Node * __thiscall CriList::insert(int,int)" (?insert@?$CriList@H@@QAEPAV?$Node@H@@HH@Z),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: class Node * __thiscall CriList::search(int)" (?search@?$CriList@H@@QAEPAV?$Node@H@@H@Z),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: void __thiscall CriList::set(int,int)" (?set@?$CriList@H@@QAEXHH@Z),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: __thiscall CriList::CriList(int * const,int)" (??0?$CriList@H@@QAE@QAHH@Z),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: int __thiscall CriList::count(void)" (?count@?$CriList@H@@QAEHXZ),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
错误 LNK2019 无法解析的外部符号 "public: int __thiscall CriList::get(int)" (?get@?$CriList@H@@QAEHH@Z),该符号在函数 _main 中被引用 ConsoleApplication2 E:\数据结构与算法暑假\ConsoleApplication2\ConsoleApplication2\main.obj 1
#include"head.h"
int main()
{
Nodenode(5);
int values[9] = { 1,2,3,4,5,7,8,9 };
CriList cl(values, 9);
if (cl.empty())
{
cout << "不为空" << endl;
}
else
{
cout << "空" << endl;
}
cout << "长度为:" << cl.count() << endl;
cout << "在3号位置的是" << cl.get(3) << endl;
cout << "把5号位置的数据替换为10" << endl;
cl.set(5, 10);
cout << "把5号位置插入为12" << endl;
cl.insert(5, 12);
cl.removeAll();
cout << "查找数据为11的数" << endl;
cl.search(11);
return 0;
}
//fun。cpp
#include"head.h"
template
CriList::CriList()//创建一个空表
{
this->head = new Node();
this->head->next = this->head;
}
template
CriList::CriList(T values[], int n)
{
int i = 0;
head = new Node();
Node*p = head;
while (i < n)
{
Node*q = new Node();
q->data = values[i];
q->next=NULL;
p->next = q;
p = q;
}
p->next = head;
printf();
}
template
bool CriList::empty()
{
return this->head->next = this->head;
}
template
int CriList::count()
{
int i = 0;
Node*q = head;
while (q->next != head)
{
i++;
}
return i;
}
template
T CriList::get(int i)
{
int j;
Nodep = head;
for(j=0;jnext!=head;j++)
{
p = p->next;
}
if (j == i)
{
return this->head->data;
}
}
template
void CriList::set(int i, T x)
{
int j;
Node*p = this->head;
for (j = 0; jnext!=head;j++)
{
p = p->next;
}
if (j == i)
{
p->data = x;
}
printf();
}
template
void CriList::printf()
{
Node*p = this->head;
while (p->next! = head)
{
cout << p->data << '\t';
}
}
template
Node CriList::insert(int i, T x)
{
int j;
Node*p = this->head;
for (j = 0; jnext != head; j++)
{
p = p->next;
}
if (j == i)
{
Node*q = new Node();
q->data = x;
q->next = p->next;
p->next = q;
}
}
template
void CriList::removeAll()
{
Node*q = head;
while (q->next != head)
{
Node*p = new Node();
p = q->next;
delete p;
p = p->next;
}
}
template
Node*CriList::search(T key)
{
Node*q = head;
while (q->next!= head)
{
q = q->next;
if (q->data == key)
{
cout << "查找正确" <
}
}
if (q->next == head)
{
cout << "查找失败" << endl;
}
}
//head.h
#include
using namespace std;
template
class Node
{
public:
T data;
Node*next;//指针域分别指向后继结点。
Node()//构造结点,data域未初始化无参构造函数
{
this->next = NULL;
}
Node(T data, Node*next = NULL)//有参构造函数,后继结点默认值为空
{
this->data = data;
this->next = next;
}
};
template
class CriList
{
public:
Node*head;//头指针
CriList();//构造空表
CriList(T values[], int n);
bool empty();//判断是否为空表
int count();//返回链表的长度
T get(int i);//返回第i个元素
void set(int i, T x);//设置第i个元素为X,虚函数
void printf();//输出循环链表
Node*insert(int i, T x);//插入x作为第i个元素
void removeAll();//清空循环链表
Node*search(T key);//查找关键字位key的元素
};