《数据结构》第二章线性表设计2:同学博客中问题求解
来源:互联网 发布:现代商友软件 编辑:程序博客网 时间:2024/05/16 08:45
各位同学,为了创建一个同学们相互学习讨论的气氛,现将同学们在自己博客是碰到的问题放出来,欢迎大家来指导,并致谢谢。请大家在本文章中集中给出自己意见。谢谢。要提醒大家的是,程序是有错误,我想也是大家可能会有的,具有一定的代表性,所以大家要考虑。
1.第二章 线性表设计2 程序求调试错误解决
同学链接: 我真的不知道错在哪里
#include<iostream> using namespace std; template<class T> struct Student { T data; Student<T> * next; }; template<class T> class LinkList { public: LinkList(); LinkList(T a[],int n); ~LinkList(); void Insert(int i,T x); T Delete(int i); void PrintList(); private: Student<T> * first; }; template<class T> LinkList<T>::LinkList() { first=new Student; first->next=NULL; } template<class T> LinkList<T>::LinkList(T a[],int n) { first=new Student;first->next=NULL; for(i=0;i<n;i++) { s=new Student;s->data=a[i]; s->next=first->next;first->next=s; } } template<class T> void LinkList<T>::Insert(int i,T x) { p=first;count=0; while(p!=NULL&&count<i-1) { p=p->next; count++; } if(p==NULL)throw"输入错误" else{ s=new Student;s->data=x; s->next=p->next;p->next=s; } } template<class T> T LinkList<T>::Delete(int i) { p=first;count=0; while(p!=NULL&&count<i-1) { p=p->next; count++; } if(p==NULL||p->next==NULL)throw"输入错误"; else{ q=p->next;x=q->data; p->next=q->next; delete q; return x; } } template<class T> void LinkList<T>::PrintList() { p=first->next; while(p!=NULL) { cout<<p->data; p=p->next; } } void main( ) { int score[5]={10, 20, 40, 50,60}; LinkList<int> ScoreList(score, 5); ScoreList.PrintList(); ScoreList.Insert(2,30); ScoreList.PrintList(); ScoreList.Delete(4); ScoreList.PrintList(); }
,翻了很多遍了都还是运行不了,所以请老师及各位大臣指点。
0 0
- 《数据结构》第二章线性表设计2:同学博客中问题求解
- 《数据结构》第二章 线性表 同学提问答案收集 分配
- 《数据结构》第二章 线性表教学设计2
- 《数据结构》第二章 线性表 问题回收站
- [数据结构]第二章--线性表(读书笔记2)
- 《数据结构》第二章 线性表 教学设计1
- 《数据结构》第二章 线性表 教学设计3
- 数据结构-----第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构 第二章 线性表
- 数据结构第二章 线性表
- 数据结构 第二章 线性表
- 【数据结构】第二章 线性表
- Android基本组件——Activity详解
- linux安装配置LAMP环境
- CentOS配置smaba与Windows共享文件
- 问题复杂度
- XMPP学习笔记(一)
- 《数据结构》第二章线性表设计2:同学博客中问题求解
- 三极管的电平转换及驱动电路分析
- leetcode-Merge Intervals
- 大型网站架构的演化
- [Java Performance] Java集合API
- 对功率谱的一点理解
- 文件操作opendir()/readdir()/closedir()/stat()
- leetcode-Word Break
- poj 1456 Supermarket