void LinkedPriorityQueue::operator += (LinkedPriorityQueue& lpq) { setfront(mergePQ(getfront(),lpq.getfront())); lpq.setfront(NULL); /* We must set the second queue's front NULL, because this method changes lpq to * a queue that shares nodes with *this. When the program finishes, if we don't * set that NULL, the running of the destructor will result in segmentation fault.*/ }
int main(){ queue que,*q; int a[5] = {10,20,30,40,50},i; q = &que; for(i=0;i<5;i++){ enqueue(q,a[i]); } i = 4; while(!empty(q)){ a[i--] = getfront(q); dequeue(q); } printf("the array elements is:\n"); for(i=0;i<5;i++){ printf("%3d ",a[i]); } }