mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-04-25 21:55:03 +02:00
53 lines
689 B
C++
53 lines
689 B
C++
|
|
//Pszeudo kód
|
|
|
|
//void* -> c# Object, Java Object, c++ template<class T>
|
|
|
|
#include <mutex>
|
|
|
|
using namespace std;
|
|
|
|
struct Node {
|
|
Node *next;
|
|
void* data;
|
|
};
|
|
|
|
class Stack {
|
|
Node head;
|
|
mutex m;
|
|
|
|
void push(void* data) {
|
|
//mutex lezár
|
|
|
|
Node *node = new Node();
|
|
node->data = data;
|
|
|
|
node->next = head.next;
|
|
head.next = node;
|
|
|
|
//mutex felold
|
|
}
|
|
|
|
void *pop() {
|
|
//mutex lezár
|
|
|
|
Node *node = head.next;
|
|
|
|
if (node == nullptr)
|
|
return nullptr;
|
|
|
|
void *data = node->data;
|
|
|
|
head.next = node->next;
|
|
|
|
delete node;
|
|
|
|
//mutex felold
|
|
|
|
return data;
|
|
}
|
|
|
|
};
|
|
|
|
|