Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.lib;
- import java.util.Scanner;
- class Queue{
- char q[];
- int putloc,getloc;
- Queue(int size){
- q=new char[size];
- putloc=getloc=0;
- }
- void put(char ch){
- if(putloc==q.length){
- System.out.println("- Очередь заполнена!");
- return;
- }
- q[putloc++]=ch;
- }
- char get(){
- if(getloc==putloc){
- System.out.println("- Очередь пуста!");
- getloc=putloc=0;
- return (char) 0 ;
- }
- return q[getloc++];
- }
- }
- class QDemo {
- public static void main(String args[])
- throws java.io.IOException {
- Queue bigQ=new Queue(100);
- Queue minQ=new Queue(5);
- int i;
- char ch;
- System.out.println("Использование bigQ для размещения букв алфавита: ");
- for(i=0;i<26;i++){
- bigQ.put((char)('A'+i));
- }
- System.out.print("Демонстрация очереди bigQ: ");
- for(i=0;i<27;i++){
- ch=bigQ.get();
- System.out.print(ch);
- }System.out.println();
- System.out.println("Использование minQ для демонстрации ошибок: ");
- for(i=0;i<6;i++){
- System.out.println("Попытка сохранения "+(char)('Z'-i));
- minQ.put((char)('Z'-i));
- }
- System.out.print("Демонстрация очереди minQ: ");
- for(i=0;i<6;i++){
- ch=minQ.get();
- System.out.print(ch);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement