Hey, i set up a circular queue to sort and pass ints easy, but having problems passing struct of information to the queue,
wat declaration should i pass to insert function??
Here is my code so far, what would i change the int item to in insert function??
have just included main, insert and remove functions
#include <iostream>
using namespace std;
void Queue_init(struct queue *the_Queue, int requiredSize);
int insert(struct queue * the_Queue, int item);
int Remove(struct queue* the_Queue ,int & item);
int peekFront(struct queue *the_Queue ,int & item);
int isEmpty(struct queue *the_Queue);
int isFull(struct queue *the_Queue);
void displayDetail(struct queue *the_Queue);
#define SIZE 50;//max size of any given stack
const int array_size = 6;
struct product
{
int prodId;
string prodName;
};
typedef struct product pArray[array_size];
struct queue
{
int Q_Array[50];
int front;
int rear;
int numItems;
int maxSize;
};
//-----------------------------------------------------------
void main()
{
struct queue aQueue;
int reqSize, success, item;
cout << "Set up queue to hold up to 6 products" << endl;
cout<< "Enter required Size of Queue"<<endl;
cin >> reqSize;
//enter struct detail
for(int i=0;i<array_size;i++)
{
cout << "enter product name" << endl;
getline(cin,pArray[i].prodName);
cout << endl;
cout << "enter prouduct id" << endl;
cin >> pArray[i].prodId;
cin.ignore();
}
Queue_init(&aQueue, reqSize);
cout << "Queue is intialised " << endl;
success = insert(&aQueue, pArray[0] );
success = insert(&aQueue, pArray[1] );
success = insert(&aQueue, pArray[2] );
success = insert(&aQueue, pArray[3] );
cout << "1 to 4 is inserted to queue" << endl;
displayDetail(&aQueue);
success = Remove(&aQueue, item);
cout << "Item is:"<< item << endl;
success = Remove(&aQueue, item);
cout << "Item is:"<< item << endl;
cout << "1 and 2 are removed from queue"<< endl;
}
//-----------------------------------------------------------
void Queue_init(struct queue *the_Queue, int requiredSize)
{
the_Queue->front= 0; //the stack is empty
the_Queue->rear = -1;
the_Queue->numItems = 0;
the_Queue->maxSize = requiredSize;
}
//-----------------------------------------------------------
int insert(struct queue * the_Queue, int item)// struct P * item)
{
if (the_Queue->numItems ==the_Queue->maxSize)
{
// put item at rear of queue
return 0;
}
else
{
if(the_Queue->rear == the_Queue->maxSize-1)
// deal with wrap around
the_Queue->rear = -1;
// increment rear and insert
the_Queue->Q_Array[++the_Queue->rear] = item;
the_Queue->numItems++; // one more item
return 1;
}
}
//-----------------------------------------------------------
int Remove(struct queue * the_Queue , int &item)//struct P &item)
{
// int i ;
// get value and incr front
if (the_Queue->numItems !=0)
{
item = the_Queue->Q_Array[the_Queue->front];
if(the_Queue->front == the_Queue->maxSize-1)
the_Queue->front =-1;
the_Queue->front++;
the_Queue->numItems--; // one less item
return 1;
}
else
return 0;
}