Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Queue {
- private String[] s = new String[1000];
- private int first = 0, last = -1;
- public boolean isEmpty(){
- return (first > last) ;
- }
- public void enqueue(String item){
- if (last == 1000) {
- System.out.println("Stackoverflow");
- return;
- }
- s[++last] = item;
- }
- public String dequeue(){
- if (isEmpty()) {
- System.out.println("Empty Stack");
- return null;
- }
- return s[first++];
- }
- public int size() {
- if (isEmpty()) return 0;
- return last - first + 1;
- }
- public static void main(String[] args){
- System.out.println("Chao cac ban");
- Queue q = new Queue();
- q.enqueue("chi");
- q.enqueue("anh");
- q.enqueue("moi");
- q.enqueue("biet");
- q.enqueue("chi");
- q.enqueue("anh");
- q.enqueue("moi");
- q.enqueue("hieu");
- q.enqueue("duoc");
- q.enqueue("em");
- while (!q.isEmpty()) {
- System.out.println("size = " + q.size());;
- System.out.println(q.dequeue());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement