#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
// element Declaration
struct element
{
int priorytet;
int data;
struct element *link;
};
// Class Priority Queue
class Kolejka_priorytetowa
{
private:
element *front;
public:
Kolejka_priorytetowa()
{
front = NULL;
}
//Insert into Priority Queue
void Dodawanie(int wart, int priorytet)
{
element *obecny, *q;
obecny = new element;
obecny->data = wart;
obecny->priorytet = priorytet;
if (front == NULL || priorytet < front->priorytet)
{
obecny->link = front;
front = obecny;
}
else
{
q = front;
while (q->link != NULL && q->link->priorytet <= priorytet)
q=q->link;
obecny->link = q->link;
q->link = obecny;
}
}
//Delete from Priority Queue
void Usuwanie()
{
element *obecny;
if(front == NULL)
cout<<"Kolejka jest pusta!\n";
else
{
obecny = front;
cout<<"Usunieto element: "<<obecny->data<<endl;
front = front->link;
free(obecny);
}
}
// Print Priority Queue
void Wyswietlanie()
{
element *wsk;
wsk = front;
if (front == NULL)
cout<<"Kolejka jest pusta!\n";
else
{ cout<<"Kolejka :\n";
cout<<"Priorytet Element\n";
while(wsk != NULL)
{
cout<<wsk->priorytet<<" "<<wsk->data<<endl;
wsk = wsk->link;
}
}
}
};
int main()
{
int wyb, wart, priorytet;
Kolejka_priorytetowa pq;
do
{
cout<<"\n1.Dodawanie elementu 2.Usuwanie elementu 3.Wyswietlanie elementu 4.Wyjscie\n";
cin>>wyb;
switch(wyb)
{
case 1:
cout<<"Podaj wartosc : ";
cin>>wart;
cout<<"Dodaj priorytet : ";
cin>>priorytet;
pq.Dodawanie(wart, priorytet);
break;
case 2:
pq.Usuwanie();
break;
case 3:
pq.Wyswietlanie();
break;
case 4:
break;
default :
cout<<"Zly wybor\n";
}
}
while(wyb != 4);
return 0;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}