problem in POPPING ARRAY QUEUE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include<iostream>
#include<stdlib.h>
#include<conio.h>

using namespace std;

const int s=50;

int f=-1, r=-1, q[s];

int insertAQ(int q[], int ele)
{
    if(r==s-1) return -1;
    else if(r==-1)
    {
        f=r=0; q[r]=ele;
    }
    else
    {
        r++; q[r]=ele;
    }
    return 0;
}

int removeAQ(int q[])
{
    int ret;
    if(f==-1) return -1;
    else
    {
        ret=q[f];
        if(f==r) f=r=-1;
        else
        {
            f++;
        }
    }
    return ret;
}

void display(int q[], int p, int o)
{
    if(p==-1) return;
    for(int i=p; i<o; i++)
        cout<<q[i]<<"<-";
    cout<<q[o]<<endl;
}



int main()
{
    int item, res, rep; char ch, hell='y';
    fronti=reari=NULL;
    int inf;
    while(hell=='y'||hell=='Y')
    {
        cout<<"==========\n";
        cout<<"   MENU\n";
        cout<<"==========\n";
        cout<<"1.Array queue push.\n2.Array queue pop.\n";
        ch=getch(); cout<<endl;
        switch(ch)
        {
        case '1':
            cout<<"\n\nEnter item to be pushed: "; cin>>item;
            res=insertAQ(q, item);
            if(res==-1)
            {
                cout<<"\n\nOVERFLOW !!\n\n"; exit(1);
            }
            cout<<"\n\nQUEUE: \n";
            display(q, f, r);
            break;

        case '2':
            rep=removeAQ[q];
            if(res==-1)
            {
                cout<<"\n\nUNDERFLOW !!\n\n"; exit(1);
            }
            else
            {
                cout<<"\n\nElement deleted is "<<res<<".\n";
                cout<<"\nQUEUE: \n";
                display(q, f, r);
            }
            break;
        }
    }
}


It gives an error in removeAQ[].

error[line 77]: invalid types 'int(int*)[int [50]]' for array subscript

Last edited on
removeAQ is a function, not an array...

perhaps you wanted this? - rep=removeAQ(q); // calling removeAQ and passing the array

You've done it correctly in case 1 - res=insertAQ(q, item);
Last edited on
Yes you are right.
Thanks.
Topic archived. No new replies allowed.