Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: small error

  1. #21
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    so could you add any value for this programme and work correct

  2. #22
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I don't know what you are going to do with Java my friend. First should know what you want/have to do. Then start work on it. Isn't it? How could I print the number 3, without knowing how to get that value at least.

    If you want to print something, you can do this.

    Java Code:
    class MyQueue {
        private int[] arr;
        private int head;
        private int tail;
        private int size;
        private int count;
    
        public MyQueue(int size) {
            arr = new int[size];
            head = 0;
            tail = 0;
            count = 0;
            this.size = size;
        }
    
        public void Enqueue(int value) {
            if(!IsFull()) {
                arr[tail] = value;
                tail = (tail + 1) % size;
                count++;
            }
            System.out.println("Enqueue gives the value: " + tail);
        }
    
        public int Dequeue() {
            if (!IsEmpty()) {
                int result = arr[head];
                head = (head + 1) % size;
                count--;
                return result;
            }
            return 0;
        }
    
        public Boolean IsFull() {
            return count == size;
        }
    
        public Boolean IsEmpty() {
            return count == 0;
        }
        
        public static void main(String[] args) {
            MyQueue mq = new MyQueue(10);
            
            mq.Enqueue(3);
            System.out.println("Dequeue give the value: " + mq.Dequeue());
        }
    }

  3. #23
    ayoood is offline Member
    Join Date
    May 2008
    Posts
    39
    Rep Power
    0

    Default

    thank you very much for your helping

  4. #24
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Page 2 of 2 FirstFirst 12

Similar Threads

  1. small issues with a program
    By jimJohnson in forum New To Java
    Replies: 6
    Last Post: 04-25-2008, 09:28 AM
  2. Building small web application in java for practice.
    By Saurabh321 in forum New To Java
    Replies: 1
    Last Post: 02-01-2008, 04:38 PM
  3. Small scale Java Editor
    By Greenfrog99 in forum AWT / Swing
    Replies: 0
    Last Post: 01-27-2008, 09:46 PM
  4. Replies: 1
    Last Post: 01-05-2008, 08:48 PM
  5. Small tennis simulation in Java
    By diego in forum New To Java
    Replies: 1
    Last Post: 12-02-2007, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •