Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication8.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct Node {
- int data;
- Node *next;
- };
- struct Queue{
- int size;
- Node* first;
- Node* last;
- };
- void Creation(Queue*Q) {
- Q->first = new Node; // выдялем память под новый элемент:
- Q->first->next = NULL;
- Q->last = Q->first;
- Q->size = 0;
- }
- void Add(Queue*Q) {
- int value;
- cout << "Value";
- cin >> value;
- Q->last->next = new Node;
- Q->last = Q->last->next;
- Q->last->data = value;
- Q->last->next = NULL; // обнуление указателя на след.элемент
- Q->size++;
- }
- int top(Queue *Q) {
- return Q->last->next->data;
- }
- bool Full(Queue*Q) {
- if (Q->first == Q->last) return true;
- else return false;
- }
- int main() {
- Queue Q;
- Creation(&Q);
- for (int i = 0; i < 5; i++) {
- Add(&Q);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement