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;
}

First things first, you might want to clean things up by moving your struct and function declarations to a header file.

Next if you change the function prototype

int insert(struct queue * the_Queue, int item)

to

int insert(struct queue * the_Queue, struct product * item)

the function declaration from

int insert(struct queue * the_Queue, struct product * item)// struct P *  item)

to

int insert(struct queue * the_Queue, struct product * item)

and

success = insert(&aQueue, pArray[0] );
success = insert(&aQueue, pArray[1] );
success = insert(&aQueue, pArray[2] );
success = insert(&aQueue, pArray[3] );

to

success = insert(&aQueue, &pArray[0] );
success = insert(&aQueue, &pArray[1] );
success = insert(&aQueue, &pArray[2] );
success = insert(&aQueue, &pArray[3] );

and move all struct declarations above your function prototypes you should be able to compile your program for testing.

If you still need help after that I should be here for a while.

the_Queue->Q_Array[++the_Queue->rear] = item;
it say illegal conversion from int to product * for this line

and expected (
getline(cin,pArray.prodName); for this line its highlighting the

any ideas why?

the_Queue->Q_Array[++the_Queue->rear] = item;

item ( is a struct )
the_Queue->Q_Array[++the_Queue->rear] ( is an int )

so unless you did

the_Queue->Q_Array[++the_Queue->rear] = item->prodId;

you wouldn't be able to set the value of the_Queue->Q_Array[++the_Queue->rear]

Thanks fixed it up it compiling now only for the ( error, i'm using the right syntax for entering and displaying struct
cin >> pArray.prodId;
success = insert(&aQueue, &pArray[0] );
but still saying [ should be (

That probably means that you made a mistake somewhere else in your program. The best way to find out where is to comment out the whole thing and then slowly uncomment each line until you find where the error is. Go ahead and give that a try.

commented: Good help +2

Ok will do, thanks for all your help!!

commented: You were very polite and gave me all the information that I needed to help you +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.