Having a problem with my code. When I type in a certain size of names I want to be enqueue it shows more names from the txt file than it should. I think I happened to fix this.
Also when I choose to print the list again, it goes in an endless loop.
How can I exactly fix this?
(txt file has like 1000+ names but I'm just using entering small capacity arrays for testing.)
#ifndef _QueueClass_
#define _QueueClass_
#include <cstdlib>
#include <string>
class Qqueue
{
public:
// Constructor
Qqueue(int cap);
// Copy Constructor
Qqueue(const Qqueue& s);
~Qqueue(); //destructor
//assignment operator
voidoperator=(const Qqueue& s);
// The member function enqueue: Precondition: the queue is not full. If the queue is full, this function signals an error.
//add value to the end of the queue
void enqueue(const std::string& s);
// The member function dequeue: Precondition: the queue is not empty. If the queue is empty, this function signals an error.
// Removes and returns the first item in the queue.
std::string dequeue();
// The member function front: Precondition: the queue is not empty.
std::string& getfront() const;
// The member function back: Precondition: the queue is not empty.
std::string& getback() const;
bool IsEmpty() const;
bool IsFull() const;
//printing all the elements in the queue
void print() const;
int size() const;
int getCapacity() const;
//Get the location of DynamicQueue at a specific index
std::string& getQueue(int);
//Returns true if the two queues contain exactly the same element values in the same order. Identical in behavior to the == operator.
bool equals(const Qqueue& q) const;
// Usage: if (q.equals(q2)) ...
private:
int Capacity; // Capacity is the maximum number of items that a queue can hold
std::string* DynamicQueue;
int num; // How many items are stored in the queue
int front;
int back;
};
#endif
#pragma once
int whaa = 0;
while (whaa < num) //where does this change..?? how do you get out?!
{
int count = front;
while (count < num)
{
std::cout << DynamicQueue[count] << "\n";
count++;
}
}
this is because you ignored common sense and made 2 variables with the same name at 2 scopes. If that code segment had been bigger, it would have taken a *while* to fix that. Do not DO that, use different names for different variables so you can see problems.
I commented out the whole printing function and it still prints names endlessly.
Guessing it has something to do with my main *while*???
I just don't know why it's doing that.
1) whatever number I want to specify the size of the array
2) Then the menu comes up so I have options to do enqueue, dequeue,save,print,etc...
I press 5 and it prints the names endlessy. Normally hitting 5 should execute the print function and display the names I have in the queue.
Well I think I figured the problem.
Im using visual studio and for some reason when I make changes to it and run, it didnt recompile it for some reason. So any changes I make is mute. Never had that happen to me before.
Guess I'll just edit it with notepad++ and compile it in unix.
Edit: Turns out I didnt even need that extra while loop at all. It works now.
IDEs designed for large projects only recompile when they detect a change, unless you hit rebuild all or whatever that is called. Unix tools can do it too, unless doing a commandline build all every time which won't work on huge projects. Its an intentional feature, but sometimes you forget to save or the file that changed is included but not in the project or various other things can cause it. unix has a touch command to solve this problem as well.