Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstring>
- #include <iostream>
- using namespace std;
- template<class T> class node {
- public:
- T data;
- node<T>* tail;
- node() {
- tail = NULL;
- }
- };
- template<class T> class stack {
- private:
- node<T>* header;
- public:
- stack() {
- header = NULL;
- }
- void push(T* obj) {
- node<T>* n = new node<T>();
- n->tail = header;
- n->data = *obj;
- header = n;
- }
- /*Начало вашего кода*/
- //TODO: Пишите код тут
- T *pop(){
- T*r=new T();
- r = &header->data;
- header = header->tail;
- return r;
- }
- /*Конец вашего кода*/
- /*Памятка! Если вы стёрли строки доступные для редактирования - нажмите F5*/
- bool empty() {
- return header == NULL;
- }
- };
- class product{
- public:
- char name[32];
- float price;
- product() {
- }
- product(char* n, float p) {
- strcpy(name, n);
- price = p;
- }
- };
- int main()
- {
- product* p1 = new product("Milk", 55.0f);
- product* p2 = new product("Bread", 10.5f);
- product* p3 = new product("Cheese", 300.0f);
- stack<product> s;
- s.push(p1);
- s.push(p2);
- s.push(p3);
- while (!s.empty())
- {
- product* tmp = s.pop();
- cout << tmp->name << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement