When I build this code, it doesn't print out anything. What is wrong with this code, I used one of the codes on the internet as a reference, it used a struct to declare queue. But I just wanted to use class. Is there any problem with using the object of the class? What are some other problems in this code?
#include<bits/stdc++.h>
using namespace std;
class Queue{
public:
int front, rear, size;
unsigned capacity;
int* array;
};
Queue* createQueue(unsigned capacity){
Queue* queue = new Queue;
queue->front = queue->size = 0;
queue->capacity = capacity;
queue->rear = queue->capacity-1;
queue->array = new int[queue->capacity];
}
int isEmpty(Queue* queue){
return (queue->size==0);
}
int isFull(Queue* queue){
return (queue->size==queue->capacity);
}
void enqueue(Queue* queue, int item){
if(isFull(queue)){
return;
}else{
queue->rear = (queue->rear+1)%queue->capacity;
queue->size = queue->size+1;
queue->array[queue->rear] = item;
cout << item << " enqueued to queue\n";
}
}
int dequeue(Queue* queue){
if(isEmpty(queue)){
return NULL;
}else{
int temp = queue->array[queue->front];
queue->front = (queue->front+1)%queue->capacity;
queue->size = queue->size-1;
return temp;
}
}
int front(Queue* queue){
if(isEmpty(queue)){
return 0;
}else{
return queue->array[queue->front];
}
}
int rear(Queue* queue){
if(isEmpty(queue)){
return NULL;
}else{
return queue->array[queue->rear];
}
}
int main(){
Queue queue;
Queue* ptr = &queue;
enqueue(ptr, 10);
}