Created
May 11, 2015 20:20
-
-
Save Wohlstand/34ca83fed43cbf7dd84c to your computer and use it in GitHub Desktop.
Очередь
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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