Pagini recente » Cod sursa (job #1705657) | Cod sursa (job #871637) | Cod sursa (job #2427410) | Istoria paginii runda/pressure/clasament | Cod sursa (job #1226519)
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;
struct Node
{
int v;
Node *next, *prev;
};
struct Queue
{
Node *head, *tail;
void Push(int v)
{
if (tail == NULL)
{
head = tail = new Node;
head->v = tail->v = v;
head->next = tail->next = NULL;
head->prev = tail->prev = NULL;
}
else
{
tail->next = new Node;
tail->next->v = v;
tail->next->next = NULL;
tail->next->prev = tail;
tail = tail->next;
}
}
void Pop()
{
if (head == NULL)
return;
if (head->next == NULL)
{
head = tail = NULL;
return;
}
head->next->prev = NULL;
head = head->next;
}
int Front()
{
if (head == NULL)
return -1;
else
return head->v;
}
};
int main()
{
Queue q;
q.head = q.tail = NULL;
q.Push(5);
q.Push(4);
cout << q.Front() << "\n";
q.Pop();
cout << q.Front() << "\n";
q.Pop();
q.Push(3);
q.Push(2);
q.Push(1);
cout << q.Front() << "\n";
return 0;
}