C++基于链式存储结构的栈的代码

将写代码过程中重要的代码片段备份一次,如下的代码段是关于C++基于链式存储结构的栈的代码。
#pragma once
#include
using namespace std;
template
class LinkNode
{
public:
T data;
public:
LinkNode()
{
}
LinkNode(T &da)
{
}

{}

};

链式栈结构中的top真的成为了一个指针,是一个结点类型指针,用来指向栈顶元素的位置。

#pragma once
#include"LinkNode.h"
#include
using namespace std;
template
class Stack
{
public:
Stack();
Stack(Stack &S);
~Stack();

};
template
Stack::Stack()
{
}
template
{

elem = srcptr->data;
newNode = new LinkNode<T>(elem);
destptr = top;
while(srcptr !=	NULL)
{

	destptr = destptr->link;
}

}
template
Stack::~Stack()
{
makeEmpty();
}
template
void Stack::makeEmpty()
{
while(top != NULL)
{
top = del->link;
delete del;
}
}
template
{
return top;
}
template
void Stack::push(T elem)
{
newNode = new LinkNode(elem);
newNode->link = top;
top = newNode;
}
template
T Stack::pop()
{
T elem;
top = del->link;
elem = del->data;
delete del;
}

template
int Stack::Length()
{
int count = 0;
while(current != NULL)
{
current = current->link;
count++;
}
return count;
}
template
bool Stack::isEmpty()
{
return ((top == NULL) ? true : false);
}
template
void Stack::output()
{
int count = 0;
while(current != NULL)
{
cout<<"#"<<count+1<<":"<data<<endl;
current = current->link;
count++;
}
}

template
void Stack::operator= (Stack &S)
{

elem = srcptr->data;
newNode = new LinkNode<T>(elem);
destptr = top;
srcptr = srcptr->link;
while(srcptr !=	NULL)
{
	cout<<"hello1"<<endl;

	destptr = destptr->link;
}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值