Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- namespace ConsoleApp2
- {
- class Kolejka<T>
- {
- private T[] tablica;
- private int head, tail;
- private bool start = true;
- public Kolejka(int rozmiar)
- {
- tablica = new T[rozmiar];
- }
- public Kolejka()
- {
- tablica = new T[10];
- }
- public void DodajListe(T[] tab)
- {
- int count = 0;
- foreach(var el in tab)
- {
- if (Dodaj(el))
- count++;
- }
- Console.WriteLine("Dodano "+count+" elementow");
- }
- public bool Dodaj(T element)
- {
- if (CzyPelna())
- return false;
- tablica[tail] = element;
- tail = (tail + 1) % tablica.Length;
- if (start)
- start = false;
- return true;
- }
- public void Usun()
- {
- if (CzyPusta())
- return;
- if ((head+1) % tablica.Length == ((tail) % tablica.Length))
- {
- head = tail = 0;
- start = true;
- }
- else
- {
- head = (head + 1) % tablica.Length;
- }
- }
- public bool CzyPusta()
- {
- if (CzyPelna())
- return false;
- if ((tail) % tablica.Length == (head) % tablica.Length && !start || start)
- {
- return true;
- }
- return false;
- }
- public void Drukuj()
- {
- int i = 0;
- Console.WriteLine("Head:"+head +" Tail:"+tail);
- foreach(T f in tablica)
- {
- Console.WriteLine("["+i+"] "+f);
- i++;
- }
- Console.WriteLine();
- }
- public void Status()
- {
- Console.WriteLine("Head == "+head);
- Console.WriteLine("Tail == " + tail);
- Console.WriteLine("Pusta? == " + CzyPusta());
- Console.WriteLine("Pelna? == "+ CzyPelna());
- }
- /*
- head = 0 tail = 0
- head = 0 tail = 1
- head = 0 tail = 2
- head = 0 tail = 3//tablica full*/
- public bool CzyPelna()
- {
- if ((tail) % tablica.Length == (head) % tablica.Length && !start)
- {
- return true;
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement