void main() { int n,q,m,w; bool pr; cin>>n>>m; Queue Q1=CreateQueue(n),Q2=CreateQueue(m); for (int i=0; i<n; i++) {cin>>q; Enq(Q1,(void*)q);} for (int i=0; i<m; i++) {cin>>q; Enq(Q2,(void*)q);} for (int i=0; i<n; i++) { pr=false; q=(int)Deq(Q1); for (int j=0; j<m; j++) { w=(int)Deq(Q2); if (q==w) pr=true; Enq(Q2,(void*)w); } if (!pr) cout<<q<<endl; Enq(Q1,(void*)q); } for (int i=0; i<m; i++) { pr=false; q=(int)Deq(Q2); for (int j=0; j<n; j++) { w=(int)Deq(Q1); if (q==w) pr=true; Enq(Q1,(void*)w); } if (!pr) cout<<q<<endl; Enq(Q2,(void*)q); } } 

    1 answer 1

    And what's the problem to endure? We look at it - it should not return anything, but Q1 Q2 should be passed as parameters. Total

     void my_func(Queue Q1, Queue Q2) { for (int i=0; i<n; i++) { pr=false; q=(int)Deq(Q1); for (int j=0; j<m; j++) { w=(int)Deq(Q2); if (q==w) pr=true; Enq(Q2,(void*)w); } if (!pr) cout<<q<<endl; Enq(Q1,(void*)q); } for (int i=0; i<m; i++) { pr=false; q=(int)Deq(Q2); for (int j=0; j<n; j++) { w=(int)Deq(Q1); if (q==w) pr=true; Enq(Q1,(void*)w); } if (!pr) cout<<q<<endl; Enq(Q2,(void*)q); } } void main() { int n,q,m,w; bool pr; cin>>n>>m; Queue Q1=CreateQueue(n),Q2=CreateQueue(m); for (int i=0; i<n; i++) {cin>>q; Enq(Q1,(void*)q);} for (int i=0; i<m; i++) {cin>>q; Enq(Q2,(void*)q);} my_func(Q1, Q2); } 

    and it's all. Of course, in real code I would write a signature a little differently, for example,

     void my_func(Queue &Q1, Queue &Q2) 

    or so

     void my_func(const Queue &Q1, const Queue &Q2) 

    these signatures will work for your code.

    • I will add that it is necessary to pass the length and the code of the cycles can be reduced by half, since Q1 and Q2 simply change places. > void my_func (Queue & Q1, Queue & Q2, int n, int m) {> int q, w; > bool pr; > for (int i = 0; i <n; i ++)> {> pr = false; > q = (int) Deq (Q1); > for (int j = 0; j <m; j ++)> {> w = (int) Deq (Q2); > if (q == w) pr = true; > Enq (Q2, (void *) w); >}> if (! pr) cout << q << endl; > Enq (Q1, (void *) q); >}>}> void main () {> ...> my_func (& Q1, & Q2, n, m); > my_func (& Q2, & Q1, m, n); } - Alex Krass