Advertisement
Master_Tiroman

Untitled

Oct 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public class EmptyExeption extends Exception{
  2. public String toString(){ return "Очередь пуста"; }
  3. }
  4.  
  5. public class FullExeption extends Exception{
  6. int size;
  7.  
  8. public FullExeption(int s){ size=s; }
  9.  
  10. public String toString(){ return "Очередь переполнена. Максималный размер: "+size+" элементов"; }
  11. }
  12.  
  13. public interface IQChar<T>{
  14. void put(T ch) throws FullExeption;
  15. T get() throws EmptyExeption;
  16. }
  17.  
  18.  
  19.  
  20. class GenQueue<T> implements IQChar<T>{
  21. private T q[];
  22. private int getloc,putloc;
  23.  
  24. GenQueue(T arr[]){
  25. q=arr;
  26. putloc=getloc=0;
  27. }
  28.  
  29. public void put(T ch)throws FullExeption{
  30. if(putloc==q.length)
  31. throw new FullExeption(q.length);
  32. q[putloc++]=ch;
  33. }
  34.  
  35. public T get()throws EmptyExeption{
  36. if(getloc==putloc) throw new EmptyExeption();
  37. return q[getloc++];
  38. }
  39. }
  40.  
  41. public class ShowFile{
  42. public static void main(String args[]) {
  43. Character mass[]=new Character[10];
  44. GenQueue<Character> ob1=new GenQueue<>(mass);
  45.  
  46. System.out.println("заполнение массива");
  47. try {
  48. for (int i = 0; i < 10; i++) {
  49. ob1.put((char) ('A' + i));
  50. }
  51. }catch (FullExeption exc){
  52. System.out.println(exc);
  53. }
  54.  
  55. System.out.println("Выдача массива:");
  56. try {
  57. for (int i = 0; i < 10; i++) {
  58. System.out.println(ob1.get());
  59. }
  60. }catch (EmptyExeption exc){
  61. System.out.println(exc);
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement