Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EmptyExeption extends Exception{
- public String toString(){ return "Очередь пуста"; }
- }
- public class FullExeption extends Exception{
- int size;
- public FullExeption(int s){ size=s; }
- public String toString(){ return "Очередь переполнена. Максималный размер: "+size+" элементов"; }
- }
- public interface IQChar<T>{
- void put(T ch) throws FullExeption;
- T get() throws EmptyExeption;
- }
- class GenQueue<T> implements IQChar<T>{
- private T q[];
- private int getloc,putloc;
- GenQueue(T arr[]){
- q=arr;
- putloc=getloc=0;
- }
- public void put(T ch)throws FullExeption{
- if(putloc==q.length)
- throw new FullExeption(q.length);
- q[putloc++]=ch;
- }
- public T get()throws EmptyExeption{
- if(getloc==putloc) throw new EmptyExeption();
- return q[getloc++];
- }
- }
- public class ShowFile{
- public static void main(String args[]) {
- Character mass[]=new Character[10];
- GenQueue<Character> ob1=new GenQueue<>(mass);
- System.out.println("заполнение массива");
- try {
- for (int i = 0; i < 10; i++) {
- ob1.put((char) ('A' + i));
- }
- }catch (FullExeption exc){
- System.out.println(exc);
- }
- System.out.println("Выдача массива:");
- try {
- for (int i = 0; i < 10; i++) {
- System.out.println(ob1.get());
- }
- }catch (EmptyExeption exc){
- System.out.println(exc);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement