Skip to content

Instantly share code, notes, and snippets.

@Wohlstand
Created May 11, 2015 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wohlstand/34ca83fed43cbf7dd84c to your computer and use it in GitHub Desktop.
Save Wohlstand/34ca83fed43cbf7dd84c to your computer and use it in GitHub Desktop.
Очередь
#include <stdio.h>
#include <alloc.h>
//Класс, это тоже структура, но с возможностью разграничивать права доступа к членам извне
class MyQueue
{
public: //Члены класса, которые НЕдоступны для внешних обращений, получишь ошибку компиляции!
struct q
{
int n;
struct q *sled;
};
q *s;
q *end;
public: //Члены класса, которые доступны для внешних обращений
MyQueue()//Это конструктор, функция, которая самовызывается в момент когда ты создаёшь переменную
{
s=0
end=0;
}
~MyQueue()//Это деструктор, функция, которая самовызывается в момент удаления переменной
{
//Самоочиситка очереди, на случай если что-то в ней было
while(old!=0)
pop();
}
void qw(int n)
{
struct q *New;
New=(struct q *)
malloc(sizeof(struct q));
New->n = n;
if(s)
{
end->sled=New;
end=N ew;
}
else
{
s=New;
end=New;
}
end->sled=0;
}
int pop()
{
struct q *old=s;
int n;
if(old)
{
n=old->n;
s=old->sled;
free(old);
}
else
{
printf("\n Очередь пуста! ");
n=0;
}
return n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment