Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.
Become a Premium Member and unlock a new, free course in leading technologies each month.
#include <iostream>
using namespace std;
#define SIZE 20
#include "queueel.h"
class QueueClass {
QueueElement* queue[SIZE];
int head, tail;
public:
QueueClass();
~QueueClass();
void qu(QueueElement* newElement);
QueueElement* dequ();
int size();
bool isEmpty();
};
QueueClass::QueueClass(): head(0) , tail(19){} // -1 is not correct init list is fine
QueueClass::~QueueClass () {}
void QueueClass::qu(QueueElement* newElement) //ok
{
//if(isEmpty()){
//queue[head]=queue[tail]=newElement;
//}
//else{
tail++;
queue[tail] = newElement;
}
QueueElement* QueueClass::dequ()
{
if (isEmpty()) {return NULL;}
else
{
head++;
return queue[head];
}
}
int QueueClass::size()
{
int counter =0;
int s;
for(s =0; s<SIZE; s++){
if (queue[s] ==queue[!NULL]){
counter++;
}
}
std::cout <<"Queue has "<<counter <<" Elements" <<std::endl;
return counter;
}
bool QueueClass::isEmpty()
{
if(size()==0) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
int QueueClass::size()
{
int tmpTail;
int size;
if(tail>=head){
tmpTail=tail;
size=tmpTail;
return size;
}
else{
tmpTail= tail+SIZE;
size=tmpTail;
}
return size;
}
bool QueueClass::isEmpty()
{
if(size()==0) {
cout << "Queue is empty\n";
return 1;
}
else return 0;
}
bool QueueClass::isEmpty()
{
if(size()==0) {
cout << "Queue is empty\n";
return isEmpty;
}
else return isEmpty;
}
#include <iostream>
using namespace std;
#define SIZE 20
#include "queueel.h"
class QueueClass {
QueueElement* queue[SIZE];
int head, tail;
public:
QueueClass();
~QueueClass();
void qu(QueueElement* newElement);
QueueElement* dequ();
int size();
bool isEmpty();
int Increment(int offset);
};
QueueClass::QueueClass(): head(0) , tail(0){} // -1 is not correct init list is fine
QueueClass::~QueueClass () {}
int QueueClass::Increment(int offset) {
offset++;
if (offset >= SIZE) offset = 0;
return offset;
}
void QueueClass::qu(QueueElement* newElement) //ok
{
// Recognize a full queue
if (Increment(tail) == head) {
std::cout << "The queue is full" << std::endl;
// Add to a not-full queue
}
else {
tail = Increment(tail);
queue[tail] = newElement;
}
}
QueueElement* QueueClass::dequ()
{
if (isEmpty()) {return NULL;}
else
{
head++;
return queue[head];
}
}
int QueueClass::size()
{
int tempTail = (tail >= head) ? tail : tail + SIZE;
int size = tempTail - head;
return size;
}
bool QueueClass::isEmpty()
{
bool isEmpty = head == tail;
if (isEmpty) cout << "Queue is empty\n";
return isEmpty;
}
#include <iostream>
using namespace std;
#define SIZE 20
class QueueClass {
int queue[SIZE];
int head, tail;
public:
QueueClass(int, int);
~QueueClass();
void qu(int num);
int dequ();
int size();
bool isEmpty();
int Increment(int offset);
};
QueueClass::~QueueClass () {}
QueueClass::QueueClass (int a, int b) {
head = a;
tail = b;
}
int QueueClass::Increment(int offset) {
offset++;
if (offset > SIZE) offset = 0;
return offset;
}
void QueueClass::qu(int num)
{
// Recognize a full queue
if (Increment(tail) == head) {
std::cout << "The queue is full" << std::endl;
// Add to a not-full queue
}
else {
queue[tail] = num; // Reversed this one
tail = Increment(tail); // ..with this one
}
}
int QueueClass::dequ()
{
if (isEmpty()) {return 0;}
else
{
//head++;
//
//return queue[head];
int tempHead = head;
head = Increment(head);
return queue[tempHead];
}
}
int QueueClass::size()
{
int tempTail = (tail >= head) ? tail : tail + SIZE;
int size = tempTail - head;
return size;
}
bool QueueClass::isEmpty()
{
bool isEmpty = head == tail;
if (isEmpty) cout << "Queue is empty\n";
return isEmpty;
}
int main()
{
QueueClass queue1(0,0);
queue1.isEmpty();
cout <<"size is " <<queue1.size() <<std::endl;
queue1.qu(1);
queue1.isEmpty();
cout <<"size is " <<queue1.size() <<std::endl;
}
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.