Код: Выделить всё
#include
using namespace std;
template
class Node{
public:
T data;
Node *next;
Node()
{
next = NULL;
}
};
class Stack
{
Node *top;
public:
Stack();
int isEmpty();
int isFull();
void push(T data);
T pop();
void display();
};
Stack :: Stack()
{
top = NULL;
}
int Stack :: isEmpty()
{
if(top == NULL)
{
return 1;
}
else
{
return 0;
}
}
int Stack :: isFull()
{
int temp;
Node *t = new Node;
if(t==NULL)
{
temp = 1;
}
else
{
temp = 0;
}
delete t;
return temp;
}
void Stack :: push(T data)
{
Node *n;
if(isFull())
{
coutnext = top;
top = n;
}
}
int Stack :: pop()
{
Node *t;
T temp;
if(isEmpty())
{
return temp;
}
else
{
t = top;
top = top->next;
temp = t->data;
delete t;
return temp;
}
}
void Stack :: display()
{
Node *p = top;
while(p != NULL)
{
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/68355352/how-to-use-template-for-implementing-stack-using-linkedlist-in-cpp[/url]