| | |
Circular Queue passing product problem
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2008
Posts: 34
Reputation:
Solved Threads: 0
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
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
C++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Mar 2009
Posts: 53
Reputation:
Solved Threads: 4
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
to
the function declaration from
to
and
to
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.
Next if you change the function prototype
C Syntax (Toggle Plain Text)
int insert(struct queue * the_Queue, int item)
C Syntax (Toggle Plain Text)
int insert(struct queue * the_Queue, struct product * item)
the function declaration from
C Syntax (Toggle Plain Text)
int insert(struct queue * the_Queue, struct product * item)// struct P * item)
C Syntax (Toggle Plain Text)
int insert(struct queue * the_Queue, struct product * item)
and
C Syntax (Toggle Plain Text)
success = insert(&aQueue, pArray[0] ); success = insert(&aQueue, pArray[1] ); success = insert(&aQueue, pArray[2] ); success = insert(&aQueue, pArray[3] );
C Syntax (Toggle Plain Text)
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.
Last edited by nexocentric; May 11th, 2009 at 9:03 am. Reason: Forgot some things
•
•
Join Date: Mar 2009
Posts: 53
Reputation:
Solved Threads: 4
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]
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]
Last edited by nexocentric; May 11th, 2009 at 9:33 am.
![]() |
Similar Threads
- Linked list implementation of a queue help (C++)
- problem with passing dynamic links (C)
- Deleting from Array Circular Queue (C++)
- Cartesian Product Problem (Oracle)
- passing parameters problem (ASP)
- queue implementation error (C++)
- help in assignment (C)
Other Threads in the C++ Forum
- Previous Thread: IPC
- Next Thread: Print Star pattern Recursively
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





