Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 527903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:55:54+00:00 2026-05-13T08:55:54+00:00

code is given below Queue<int> queXpTrackerX = new Queue<int>(10); Queue<int> queXpTrackerY = new Queue<int>(10);

  • 0

code is given below

Queue<int> queXpTrackerX = new Queue<int>(10);
Queue<int> queXpTrackerY = new Queue<int>(10);       

if (iCounterForXpTrack < 10)
{
    queXpTrackerX.Enqueue(X);
    queXpTrackerY.Enqueue(Y);
    iCounterForXpTrack++;
}//End IF
else
{
    queXpTrackerX.Dequeue();
    queXpTrackerY.Dequeue();
    queXpTrackerX.Enqueue(X);
    queXpTrackerY.Enqueue(Y);
}//End else

for (int indexXp = 0; indexXp < iCounterForXpTrack; indexXp++)
{
    gXpTracker.DrawEllipse(Pens.Cyan, queXpTrackerX.ElementAt(indexXp) , queXpTrackerY.ElementAt(indexXp), 5, 5);
}//end for
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:55:55+00:00Added an answer on May 13, 2026 at 8:55 am

    I suspect that the most likely cause for you InvalidOperationException is trying to Dequeue from a queue when it is empty. Did you have the exception message? Is it ‘Queue empty.’?

    This can happen if your iCounterForXpTrack becomes out of sync with the number of elements in the queue. It would be better to just ask the queue directly to avoid this possible error:

        if (queXpTrackerX.Count < 10)
        {
            queXpTrackerX.Enqueue(X);
            queXpTrackerY.Enqueue(Y);
        }
        else
        {
            queXpTrackerX.Dequeue();
            queXpTrackerY.Dequeue();
            queXpTrackerX.Enqueue(X);
            queXpTrackerY.Enqueue(Y);
        }
    

    A possible reason that your code fails is if you initialized iCounterForXpTrack to 10 thinking that new Queue<int>(10) creates a queue that starts with 10 elements. This is not the case. The queue is initially empty. Providing the capacity to the queue constructor is just a performance optimization and is not strictly needed.

    Another issue with your code: instead of having two queues, one for x and one for y, you should use some sort of Point class and a Queue<Point>. This simplifies the code and eliminates possible errors from the two queues becoming out of sync.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for the Given below code after int Input Value of 46348 i am getting
I'm new for jquery..... i have a doubt in the code given below..... if
In the code given below, I need to position the userid box in the
In the code given below, I am trying to modify it in such a
Hello friends i am running code given below which contains the setLogTimeEntery function and
Technology Used:- Asp.Net 2.0 Code:- See Below Description:- hello code given below is working
I have Depth first searching algorithm whose pseudo code is given below: DFS(Vertex v)
I am creating a form in CakePHP.A snippet of the code is given below.
I'm trying to get familiar with ViewPager. My code is given below. The problem
How to know the Id of item I clicked? my code is given below:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.