Queues program suddenly stops working

I'm having troubles with this program I made. Put it simply, it's a basic program using Queues. Whenever I try to input a value, my compiler(Dev C) suddenly stops working. The .exe file crashes and I've no way on how I can execute my program.

This is my program:
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
#include<iostream>
using namespace std;
int *queue;
int rear, front, queueSize;
void enqueue();
void dequeue();
void display();
int main()
{
    int choice;
    int element;
    cout<<"Enter element number: "; cin>>element;
    system("cls");
	while(choice!=4)
        {
        cout<<"****************"<<endl;
	    cout<<"[1] - Enqueue" << endl << "[2] - Dequeue" << endl << "[3] - Display" << endl << "[4] - Exit" << endl;
	    cout<<"-----------------"<<endl;
	    cin>>choice;
	    
	    switch(choice)
	    {
           case 1:
                enqueue();
                break;
           case 2:
                dequeue();
                break;
           case 3:
                display();
                break;
           case 4:
                break;
        }
        }
        cin.get();
        }
        
 void enqueue()
{
  if (rear == (queueSize-1))
    {
      cout<<"\n Overflow! No space left in Queue. Cannot push.";
 
    }
  else
    {
      rear++;
      cout<<"\n Enter the element to be pushed in Queue : ";
      cin>>queue[rear];	
    }
}
 
void dequeue()
{
  if (front == rear)
    {
      cout<<"\n Underflow! Cannot pop any items because Queue is empty.";
    }
  else
    {
      cout<<"\n The element that was popped was : "<<queue[++front];
    }
}
 
void display()
{
  if (front == rear)
    {
      cout<<"\n Queue is empty, no element to display";
    }
  else
    {
      for(int i = (front+1); i<=rear; i++)
	{
	  cout<<queue[i];
	  if (i != rear)
	    {
	      cout<<"<--";
	    }
	}
    }
}


Any ideas on how I can fix this? Any help would be much appreciated.
A lot of things don't make sense here.

1. You did not declare a queue ADT(abstract data type) or memory for queue

2. Line 41 will always be false because you never gave those variables a value (line 8)

3. Line 50, queue is a pointer (line 3) by itself, but you are trying to access it like it is pointing to a chunk of memory


The first thing I will recommend fixing is to actually create a new queue by first allocating memory for it (int * queue = new int[SIZE];), then give all those variables on line 8 a value
Topic archived. No new replies allowed.