程序那里出错了,大家看看!
#include<iostream>
template<class T>class List
{
public:
List();
void Add(T&);
void Remove(T&);
T* Find(T&);
void PrintList();
~List();
protected:
struct Node{
Node* pNext;
T* pT;
};
Node* pFirst;
};
template<class T>List<T>::List()
{
pFirst=0;
}
template<class T>
void List<T>::Add(T& t)
{
Node* temp=new Node;
temp->pT=&t;
temp->pNext=pFirst;
pFirst=temp;
}
template<class T>void List<T>::Remove(T& t)
{
Node* q=0;
if(*(pFirst->pT)==t)//在结构的头
{
q=pFirst;
pFirst=pFirst->pNext;
}
else
{
for(Node* p=pFirst;p->pNext;p=p->pNext)
if(*(p->pNext->pT)==t)
{
q=p->pNext;
p->pNext=q->pNext;
break;
}
}
if(q){
delete q->pT;
delete q;
}
}
template<class T>
T* List<T>::Find(T& t)
{
for(Node* p=pFirst;p;p=p->pNext)
{
if(*(p->pT)==t)
return p->pT;
}
return 0;
}
template<class T>
void List<T>::PrintList()
{
for(Node* p=pFirst;p;p=p->pNext)
{
cout<<*(p->pT)<<" ";
}
cout<<endl;
}
template<class T>
List<T>::~List()
{
Node* p;
while(p=pFirst)
{
pFirst=pFirst->pNext;
delete p->pT;
delete p;
}
}
void main()
{
List<float> floatList;
for(int i=1;i<7;i++)
{
floatList.Add(*new float(i+0.6));
}
floatList.PrintList();
float b=3.6;
float* pa=floatList.Find(b);
if(pa)
{
floatList.Remove(*pa);
}
floatList.PrintList();
}
...全文
相关推荐
程序游戏不再出错!Windows常用运行库下载for 64(64位机)
完美解决 Windows下运行软件时 提示的VC++Runtime Error错误。Windows 64位下使用
程序游戏不再出错!Windows常用运行库下载for x86(32位机)
程序游戏不再出错!Windows常用运行库下载for x86(32位机) 完美解决 Windows平台上软件或游戏运行时提示的 VC++ Runtime Error问题
由于存在问题多,程序出错建议不要下载该版本
由于存在问题多,程序出错建议不要下载该版本 多数手机安装后无法启动建议使用 蓝田之景1.1 版,该版本修复了所有已知问题,并且相当稳定,目前尚未发现有问题!蓝田之景1.1 版,下载资源分为 0 !现在这个的资源分为 10 !
补丁针对生成的易语言调用DLL出错
补丁针对生成的易语言调用DLL出错的程序: ---------- 错误 ----------- “运行时出错!错误代码:6错误信息:调用DLL命令后发现堆栈错误”. ---------------------------------------------------------------- (使用前,把要补丁的程序重命名为123.exe)
asp.net网站出错时如何处理?
asp.net网站出错时如何处理?


