线性表实验二 以失败告终
来源:互联网 发布:linux查看80端口 编辑:程序博客网 时间:2024/05/17 20:32
挣扎了两个星期之后,线性表的实验失败了,败在一个非常郁闷的地方:调试不过。
不知道发什么神经,之后我又用实验书里面的代码试了一下,坑爹的又是调试不过。书上完整代码如下:
(头文件)
#ifndef LinkList_H#define LinkList_Htemplate<class DataType>struct Node{DataType data;Node<DataType> * next;};template<class DataType>class LinkList{public:LinkList();LinkList(DataType a[],int n);~LinkList();int Locate(DataType x);void Insert(int i,DataType x);DataType Delete(int i);void PrintList();private:Node<DataType> * first;};#endif
(源文件)
#include<iostream>using namespace std;#include"LinkList.h"template<class DataType>LinkList<DataType>::LinkList(){first=new Node<DataType>;first->next=NULL;}template<class DataType>LinkList<DataType>::LinkList(DataType a[],int n){Node<DataType> * r,* s;first=new Node<DataType>;r=first;for(int i=0;i<n;i++){s=new Node<DataType>;s->data=a[i];r->next=s;r=s;}r->next=NULL;}template<class DataType>LinkList<DataType>::~LinkList(){Node<DataType> * q=NULL;while(first!=NULL){q=first;first=first->next;delete q;}}template<class DataType>void LinkList<DataType>::Insert (int i,DataType x){Node<DataType> * p=first,* s=NULL;int count=0;while(p!=NULL && count<i-1){p=p->next;count++;}if(p==NULL) throw"location";else{s=new NodeV;s->data=s;s->next=p->next;p->next=s;}}template<class DataType>DataType LinkList<DataType>::Delete (int i){Node<DataType> * p=first, * q=NULL;DataType x;int count=0;while(p!=NULL && count<i-1){p=p->next;count++;}if(p==NULL||p->next==NULL)throw"location"else{q=p->next;x=q->data;p->next=q->next;delete q;return q;}}template<class DataType>int LinkList<DataType>::Locate (DataType x){Node<DataType> * p=first->next;int count=i;while(p!=NULL){if(p->data==x) return count;p=p->next;}return 0;}template<class DataType>void LinkList<DataType>::PrintList (){Node<DataType> * p=first->next;while(p!=NULL){cout<<p->data<<" ";p=p->next;}cout<<endl;}
(”main“源文件)
#include<iostream>using namespace std;#include"LinkList.cpp"void main(){int r[5]={1,2,3,4,5};Linklist<int>L(r,5);cout<<"show the data that are before inserting: "<<endl;L.PrintList();try{L.Insert(2,3);}catch (char * s){cout<<s<<endl;}cout<<"apply the order that insert the data and show them: "<<endl;L.PrintList();cout<<"the location of the element whose number is 5 directs: ";cout<<L.Locate(5)<<endl;cout<<"show the data that are infron the operation of delection: "<<endl;L.PrintList();try{L.Delect(1);}catch(char * s){cout<<s<<end}L.PrintList();}
F:\c++文件\单链表验证实验\LinkList_main.cpp(7) : error C2065: 'Linklist' : undeclared identifier
F:\c++文件\单链表验证实验\LinkList_main.cpp(7) : error C2062: type 'int' unexpected
F:\c++文件\单链表验证实验\LinkList_main.cpp(9) : error C2065: 'L' : undeclared identifier
F:\c++文件\单链表验证实验\LinkList_main.cpp(9) : error C2228: left of '.PrintList' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(12) : error C2228: left of '.Insert' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(19) : error C2228: left of '.PrintList' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(21) : error C2228: left of '.Locate' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(23) : error C2228: left of '.PrintList' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(26) : error C2228: left of '.Delect' must have class/struct/union type
F:\c++文件\单链表验证实验\LinkList_main.cpp(32) : error C2228: left of '.PrintList' must have class/struct/union type
执行 cl.exe 时出错.
单链表验证实验.exe - 1 error(s), 0 warning(s)
是书上代码不完整么?但事实上它显示的错误是main文件上面的类成员没有定义类型,但是我们都看到在一开始类类型就已经被定义了,并且在main函数中也把类文件引入了(请参看main文件的头文件),这是怎么回事?先前我以为是自己的代码问题,还重写了几次,现在连实验书的代码都出错,而且可以看到,这个错误看起来有些不合理。问题出在什么地方?
顺便说一下,我用的是绿色版,这个跟版本应该无关。
- 线性表实验二 以失败告终
- 昨天的谈判以失败而告终。。。。
- 初创企业为何多以失败告终
- 2007-04-25 02:17考研以失败告终 [原]
- [转]Gartner:绝大多数VR项目以失败告终
- MyEclipse7.5安装CDT以失败告终结尾了。
- 初次接触回调函数--以失败告终
- 服务器网络性能调优的尝试,以失败告终
- 为何多数的大数据项目以失败告终?
- 寻路题目,以失败告终。先保存一下
- 实验二:线性表实验
- 实验二:线性表实验
- 实验二:线性表实验
- 实验二线性表实验
- 实验二 线性表实验
- 实验二、 线性表实验
- 数据结构实验二------线性表
- 实验二之线性表
- GC入门指南(三)----垃圾收集器类型
- linux下压缩解压缩命令
- android 中的 window,view,activity具体关系
- YARN(Hadoop)学习笔记(3)
- C#文字的复制,剪切,撤销
- 线性表实验二 以失败告终
- C指针编程之道 ---第一次笔记
- Play on Words - UVa 10129 欧拉回路
- asp.net中母版页与内容页加载顺序
- Wikioi P1067 机器翻译
- iOS 工作中遇到的一个tableView设计
- 第九周 项目六 穷举法解决组合问题3
- C语言编程100例之4
- 黑马程序员--Java基础之开发前奏