Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct kolejka
- {
- const int n=7;
- int head=7;
- int tail=1;
- int tab[7];
- };
- bool empty(kolejka &q)
- {
- if (q.head==q.tail)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- void enqueue (kolejka &q, int x)
- {
- if (q.tail+1==q.head || q.head==1 && q.tail==q.n)
- {
- cout<<"pusta"<<endl;
- }
- else
- {
- q.tab[q.tail]=x;
- if (q.tail==q.n)
- {
- q.tail=1;
- }
- else q.tail=q.tail+1;
- }
- }
- int dequeue(kolejka &q)
- {
- if (empty(q))
- {
- cout<<"error"<<endl;
- return -1;
- }
- else
- {
- int x=q.tab[q.head];
- if (q.head==q.n)
- {
- q.head=1;
- }
- else
- {
- q.head=q.head+1;
- }
- return x;
- }
- }
- int main()
- {
- kolejka Q;
- enqueue(Q,1);
- enqueue(Q,2);
- enqueue(Q,3);
- enqueue(Q,4);
- enqueue(Q,5);
- cout<<dequeue(Q)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement