关于栈的问题!
1:利用链表模拟栈
2:演示栈的基本操作
3:栈采用模板,栈的节点需要是一个描述学生记录的类对象
(帮小弟改一改吧!!!我都要疯拉!!!!我用的 是两个文件存放的,header,souce)
template<class T>
class genabstractstack
{
protected:
unsigned height;
public:
bool isenpty()
{
return(height==0)?true:false;
}
virtual void push(T &)=0;
virtual bool pop(T &)=0;
virtual void clear()=0;
virtual void check()=0;
};
template<class T>
struct genstackrec
{
T nodedata;
genstackrec * next;
};
template<class T>
class genstack:public genabstractstack<T>
{ protected:
bool allocateerror;
genstackrec<T> * top;
genstack & copy(genstack &);
public:
genstack();
genstack(genstack & g)
{
top=NULL;copy(g);
}
~genstack()
{clear();}
bool getallocateerror()
{return allocateerror;}
virtual void clear();
virtual void push(T &x);
virtual bool pop(T & x);
virtual void check(T & x);
genstack & operator=(genstack & g)
{copy(g);return * this;}
};
template<class T>
genstack<T>::genstack()
{
height=0;
allocateerror=false;
top=NULL;
}
template<class T>
genstack<T>&genstack<T>::copy(genstack<T>&g)
{
genstackrec<T> *p,*q,*r;
if(top)clear();
height=g.height;
allocateerror=false;
top=NULL;
if(! g.top)
return * this;
top=new genstackrec<T>;
if(! top)
{
allocateerror=true;
return * this;
}
top->next=NULL;
top->nodedata=g.top->nodedata;
q=g.top->next;
p=top;
while(q)
{
r=new genstackrec<T>;
if(! r)
{allocateerror=true;
return * this;
}
r->nodedata=q->nodedata;
r->next=NULL;
p->next=r;
p=p->next;
q=q->next;
}
return * this;
}
template<class T>
void genstack<T>::clear()
{
T x;
while(pop(x));
}
template<class T>
void genstack<T>::push(T & x)
{
genstackrec<T> * p;
allocateerror=false;
if(top)
{
p=new genstackrec<T>;
if(!p)
{
allocateerror=true;
return;
}
p->nodedata=x;
p->next=top;
top=p;
}
else
{
top==new genstackrec<T>;
if(!top)
{
allcocateerror=true;
return;
}
top->nodedata=x;
top->next=NULL;
}
height++;
}
template<class T>
bool genstack<T>::pop(T & x)
{
genstackrec<T> * p;
if(height)
{
x=top->nodedata;
p=top;
top=top->next;
delete p;
height--;
return true;
}
return false;
}
template<class T>
void genstack<T>::check(T & p)
{
T temp;
if(top==0)
{
cout<<"栈为空,不能进行数据查询!"<<endl;
//exit(1);
}
else
for(int n=0;n<6;n++)
{
temp=s[top-n];
if(p!=temp)
{}
else
{cout<<"该数据在栈中。"<<endl;
break;}
if(n==top-n)cout<<"该数据不在栈中。"<<endl;
}
}
#include "stdafx.h"
#include<string.h>
#include<stdio.h>
#include<dos.h>
#include<iostream.h>
class student
{
public:
char name[80];
int age;
float mark_average;
char sex[8];
//void assign(char *name,int age,float mark_average,char *sex);
void print();
};
//void student::assign(char *name,int age,float mark_average,char *sex);
//{strcpy(student::name,name);student::age=age;student::mark_average=mark_average;strcpy(student::sex,sex);
//}
void viewstack(genstack<student> & stack)
{
student p;
int i=1;
genstack<student> stackcopy(stack);
//clrscr();
while(stackcopy.pop(p))
{
gotoxy(1,i+5);
printf("%2d:",i++);
p.print();
}
}
main()
{
genstack g;
for(s=0;s<80;s++)
{ cin>>s;
g.push(s);
}
student s;
while(stack.pop(s))
{
viewstack(stack);
delay(1000);
}
stack.clear();
return 1;
}
--------------------Configuration: ll - Win32 Debug--------------------
Compiling...
ll.cpp
d:\ll\stdafx.h(145) : error C2244: 'genstack<T>::push' : unable to resolve function overload
d:\ll\stdafx.h(146) : error C2954: template definitions cannot nest
d:\ll\ll.cpp(27) : error C2259: 'genstack<class student>' : cannot instantiate abstract class due to following members:
d:\ll\ll.cpp(27) : warning C4259: 'void __thiscall genabstractstack<class student>::push(int)' : pure virtual function was not defined
d:\ll\stdafx.h(30) : see declaration of 'push'
d:\ll\ll.cpp(27) : warning C4259: 'void __thiscall genabstractstack<class student>::check(void)' : pure virtual function was not defined
d:\ll\stdafx.h(33) : see declaration of 'check'
d:\ll\ll.cpp(27) : error C2259: 'genstack<class student>' : cannot instantiate abstract class due to following members:
d:\ll\ll.cpp(27) : warning C4259: 'void __thiscall genabstractstack<class student>::push(int)' : pure virtual function was not defined
d:\ll\stdafx.h(30) : see declaration of 'push'
d:\ll\ll.cpp(27) : warning C4259: 'void __thiscall genabstractstack<class student>::check(void)' : pure virtual function was not defined
d:\ll\stdafx.h(33) : see declaration of 'check'
d:\ll\ll.cpp(31) : error C2065: 'gotoxy' : undeclared identifier
d:\ll\ll.cpp(39) : error C2955: 'genstack' : use of class template requires template argument list
d:\ll\stdafx.h(65) : see declaration of 'genstack'
d:\ll\ll.cpp(39) : error C2133: 'g' : unknown size
d:\ll\ll.cpp(39) : error C2512: 'genstack' : no appropriate default constructor available
d:\ll\ll.cpp(39) : error C2262: 'g' : cannot be destroyed
d:\ll\ll.cpp(40) : error C2065: 's' : undeclared identifier
d:\ll\ll.cpp(45) : error C2065: 'stack' : undeclared identifier
d:\ll\ll.cpp(45) : error C2228: left of '.pop' must have class/struct/union type
d:\ll\ll.cpp(45) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
ll.exe - 13 error(s), 4 warning(s)
相关推荐
前端开发组件示例源码_f1b6a91d详解
前端开发组件示例源码_f1b6a91d,内容包含源码/脚本与使用说明文档,结构清晰、注释完整,适合学习参考与二次开发,下载解压即可查看。
前端开发基于history.js的HTML5与HTML4浏览器兼容方案:单页应用无刷新历史状态管理技术实现-Gjl4Gf1792158475
内容概要:本文系统介绍了如何利用history.js实现单页应用(SPA)在HTML5c与HTML4浏览器间s草错发的无缝历史状态管理。通过封装原生History API并在不支持的浏览器中自动降级为哈希路由,history.js解决了因浏览器兼容性导致的后退按钮失效、URL混乱等问题。文章详细讲解了其核心机制,包括状态对象管理、自动模式切换(HTML5 pushState vs HTML4 哈希)、状态数据持久化以及针,对Safari、IE等浏\览器的兼容性修复方案,并提供了从入门到实战的完整示例,涵盖初始化、事,件监听、页面加载及性能优化技巧。;Gjl4Gf1792158475 www.gblp.net www.gsctlq.com gezhixq.cn www.greendalian.com wap.gxqnm.com
前端开发基于history.js的HTML5与HTML4浏览器兼容方案:单页应用无刷新历史状态管理技术实现-5Z6jeSqI1792158476
内容概要:本文系统介绍了如何利用history.js实现单页应用(SPA)在HTML5c与HTML4浏览器间s草错发的无缝历史状态管理。通过封装原生History API并在不支持的浏览器中自动降级为哈希路由,history.js解决了因浏览器兼容性导致的后退按钮失效、URL混乱等问题。文章详细讲解了其核心机制,包括状态对象管理、自动模式切换(HTML5 pushState vs HTML4 哈希)、状态数据持久化以及针,对Safari、IE等浏\览器的兼容性修复方案,并提供了从入门到实战的完整示例,涵盖初始化、事,件监听、页面加载及性能优化技巧。;5Z6jeSqI1792158476 sdhmgggw168.com www.shangliangwangye.com www.sdbing.net migu.blsxex.abxlbz.sc.cn www.safespeed.net.cn
高校如何通过科技报告服务提升技术转移转化效率?.docx
科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。
科技服务机构如何提升服务大企业的技术诊断能力?.docx
科技服务机构如何提升服务大企业的技术诊断能力?


