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 8755057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:46:11+00:00 2026-06-13T13:46:11+00:00

I am trying to print the contents of a queue as an array. I

  • 0

I am trying to print the contents of a queue as an array. I have the code working and compiling. The problem is when I call the function more than once the print function does not call and the array is not printed again. I need to print the array more than once and it does not print.

The code for the Print function is :

template <class Type>
 void queueType<Type>::debugArray() 
 {
   for(queueFront; queueFront<count; queueFront++){
    cout << "[" << queueFront<< "] ," << list[queueFront] << " ";
   }

 } //end debugQueue

The main.cpp code is:

#include <iostream>
#include "queueAsArray.h"

using namespace std;

int main()
{
    queueType<int> q1;
    queueType<int> q2;
    queueType<int> q3;
    int x = 5;

    for(int i= 0; i<10; i++) {
        q1.addQueue(i);
    }

    cout << "q1 after being filled up with 10 items" << endl;

    q1.printQueueInfo();

    cout << "Queue contents from front to rear\n\n" << endl;

    q1.debugArray();
    q1.deleteQueue();
    q1.deleteQueue();
    q1.deleteQueue();

    for(int i= 0; i<=20; i){
        i+=5;
        q1.addQueue(i);
    }

    q1.debugArray();
    return 0;
}

Is there a reason why the function call will not print again? If you need the entire class and implementation file I can supply it. The weird thing is if I create a second instatiation of the class q2, then build an array for q2, the debugQueue function prints that queue. I then call the overloaded assignment operator and do q2=q1, then call debugQueue Again and it prints the contents of the queue. So I am confused as why it will print the second queue twice, but not the first queue.
Any thoughts?

  • 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-06-13T13:46:13+00:00Added an answer on June 13, 2026 at 1:46 pm

    It looks like your problem is that you’re mutating the queueType instance as a part of the printing.

    template <class Type>
    void queueType<Type>::debugArray() 
    {
      for(queueFront; queueFront<count; queueFront++){
        cout<<"[" << queueFront<<"] ,"<< list[queueFront]<<" ";}
    } 
    

    Here you are taking the member queueFront and mutating it forward until you hit the end of the queue. This is mutating the field queueFront instead of a local which points to the same location. Try using a local and it will fix your problem

    for(auto current = queueFront; current < count; current++){
      cout<<"[" << current<<"] ,"<< list[current]<<" ";}
    } 
    

    Note: I used auto for the type because I didn’t know the type of queueFront. I assume it’s list<int>::iterator but wasn’t sure. You can replace auto with the correct type or leave it as is and let the compiler infer the type of current

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

Sidebar

Related Questions

I'm trying to write a function that will print the contents of both minheap
I'm trying to print the contents of an array to the screen, but nicely
I'm trying to call c functions from python, I have the following code in
I have a JTextComponent (JTextArea). I am trying to print its contents with using
i have a question for you guys. im trying to print an array where
I'm trying to print the elements of a page using this code: $('#some_button').click(function(){ var
I am having a small problem I am trying to print the contents of
I'm so dang close. I'm trying to print the contents of a form to
I am trying to print the page by java script. The code is like
I am trying to print the remaining contents of a file after I do

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.