Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // magacin
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- public abstract class Magacin
- {
- private int kapacitet;
- private int popunjenost;
- public Magacin(int a)
- {
- kapacitet = a;
- popunjenost = 0;
- }
- public int Kapacitet
- {
- get
- {
- return kapacitet;
- }
- }
- public bool isEmpty
- {
- get
- {
- if (popunjenost == 0)
- return true;
- else
- return false;
- }
- }
- public bool isFull
- {
- get
- {
- if (popunjenost == kapacitet)
- return true;
- else
- return false;
- }
- }
- public int Popunjenost
- {
- get
- {
- return popunjenost;
- }
- set
- {
- popunjenost = value;
- }
- }
- public abstract void push(int x);
- public abstract int pop();
- }
- }
- // kao vektor
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class MagacinKaoVektor : Magacin
- {
- private int[] niz;
- private int pok;
- public MagacinKaoVektor(int a)
- : base(a)
- {
- niz = new int[a];
- pok = -1;
- }
- public override int pop()
- {
- if (!isEmpty)
- {
- int pom = niz[pok];
- if (--pok < 0)
- pok = Kapacitet;
- Popunjenost = Popunjenost - 1;
- return pom;
- }
- else
- Console.WriteLine("Magacin je prazan");
- return 0;
- }
- public override void push(int x)
- {
- if (!isFull)
- {
- if (++pok == Kapacitet)
- pok = 0;
- Popunjenost = Popunjenost + 1;
- niz[pok] = x;
- }
- else
- Console.WriteLine("Magacin je pun");
- }
- }
- }
- // mejn
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- MagacinKaoVektor mag = new MagacinKaoVektor(10);
- mag.push(121);
- mag.push(2);
- mag.push(342);
- mag.push(424);
- mag.push(575);
- mag.push(675);
- mag.push(723);
- mag.push(458);
- mag.push(921);
- mag.push(10);
- mag.push(989898);
- for (int i = 0; i < 11; i++)
- Console.WriteLine(mag.pop());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement