Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- using namespace std;
- //TABLICOWA REALIZACJA KOLEJKI
- #define LIMIT 100
- int QUEUE[LIMIT];
- int first,last,size;
- void display()
- {
- for(int i=0;i<size;i++)
- {
- cout<<QUEUE[(first+i)%LIMIT]<<" ";
- }
- }
- void create()
- {
- first=0;
- last=LIMIT-1;
- size=0;
- }
- bool is_empty()
- {
- if(size==0)return true;
- else return false;
- }
- void insert(int x)
- {
- if(size==last)cout<<"OVERFLOW"<<endl;
- else
- {
- size++;
- last=(last+1)%LIMIT;
- QUEUE[last]=x;
- }
- display();
- }
- void First()
- {
- if(size==0)cout<<"QUEUE IS EMPTY!"<<endl;
- else
- cout<<QUEUE[first]<<endl;
- display();
- }
- void Delete()
- {
- if(size==0)cout<<"QUEUE IS EMPTY!"<<endl;
- else
- size=size-1;
- first=(first+1)%LIMIT;
- display();
- }
- int main()
- {
- cout<<"==================================="<<endl;
- cout<<"MENU"<<endl;
- cout<<"==================================="<<endl;
- cout<<"1. TWORZENIE KOLEJKI"<<endl;
- cout<<"2. SPRAWDZANIE, CZY KOLEJKA JEST PUSTA"<<endl;
- cout<<"3. WSTAWIANIE ZADANEGO ELEMENTU DO KOLEJKI"<<endl;
- cout<<"4. WYSWIETLANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
- cout<<"5. USUWANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
- cout<<"6. KONIEC PROGRAMU(KAZDY INNY KLAWISZ ROWNIEZ KONCZY PROGRAM)"<<endl;
- int command=0;
- cout<<endl;
- cout<<"PODAJ NUMER POLECENIA : ";
- cin>>command;
- while(command!=6)
- {
- if(command==1)
- {
- create();
- }
- else if(command==2)
- {
- if(is_empty())
- cout<<"KOLEJKA JEST PUSTA"<<endl;
- else
- cout<<"KOLEJKA NIE JEST PUSTA"<<endl;
- }
- else if(command==3)
- {
- cout<<"PODAJ ELEMENT, KTORY CHCESZ WSTAWIC DO KOLEJKI: "<<endl;
- int x;
- cin>>x;
- insert(x);
- }
- else if(command==4)
- {
- First();
- }
- else if(command==5)
- {
- Delete();
- }
- else
- {
- break;
- }
- Sleep(1000);
- system("cls");
- cout<<"==================================="<<endl;
- cout<<"MENU"<<endl;
- cout<<"==================================="<<endl;
- cout<<"1. TWORZENIE KOLEJKI"<<endl;
- cout<<"2. SPRAWDZANIE, CZY KOLEJKA JEST PUSTA"<<endl;
- cout<<"3. WSTAWIANIE ZADANEGO ELEMENTU DO KOLEJKI"<<endl;
- cout<<"4. WYSWIETLANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
- cout<<"5. USUWANIE PIERWSZEGO ELEMENTU KOLEJKI"<<endl;
- cout<<"6. KONIEC PROGRAMU(KAZDY INNY KLAWISZ ROWNIEZ KONCZY PROGRAM)"<<endl<<endl;
- cout<<"PODAJ NUMER POLECENIA : ";
- cin>>command;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement