Im trying to make a circular queue. Why does empty keep saying my q is empty?

using System;

namespace CQueue
{
    class Program
    {
        static void Main(string[] args)
        {
            List queue = new List();

            Double number = 9.13;

            queue.Enqueue(number);
            queue.Enqueue(number);
           
            queue.PrintQueue();
        }
    }
}
class List
{
    object[] thisIsQ = new object[10];
    int head = 0;
    int tail = 0;

    public void Enqueue(object insert)
    {
        if (IsEmpty())
        {
            thisIsQ[tail] = insert;
            tail = Counter(tail);
        }
    }

    public void PrintQueue()
    {
        if (Empty())
        {
            Console.WriteLine("Queue is Empty.");
        }
    }

    public bool Empty()
    {
        return (tail == 0 && head == 0);
    }

    public int Counter(int x)
    {
        return (x) % thisIsQ.Length;
    }
}
if (IsEmpty())
        {
            thisIsQ[tail] = insert;
            tail = Counter(tail);
        }

You've not IsEmpty method. or you mean Empty?

When you call this:

tail = Counter(tail);

variable tail not gonna change. Your initial value of tail is 0 and if you'll divide it by some number - it will give you 0.

yeah I mean Empty

So, debug your code :) you'll see if Antenka got the solution or not.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.