Hi folks! I have written one program, which works ok, compiles etc. But I have one problem with it: when i am trying to debug it i am getting the following error: "access violation segmentation fault raised in your program", it just pops up as a window and i can't even debug my program at all. I am using devc++ with it.If any one know how to fix this stupid proble, please reply asap.Any help is appreciated.Thanks.
Heres the code:
Code:#include<iostream> #include<iomanip> #include<conio.h> using namespace std; const int MAX = 10; class LinearQueue { private: int queue[MAX]; int rear; int front; public: //LinearQueue(); void Queue(); void Delete(); void Insert(); void print_queue(); void show_working(); }; void LinearQueue::Queue() { rear=-1; front=-1; for(int count=0;count < MAX;count++) queue[count]=0; } void LinearQueue::Insert() { int item; cout << setw(40) << "\n\n\n\n\n\t Enter value to insert into the Queue : " << endl << endl; cin >> item; if(rear == (MAX-1)) cout << "\n\n\t *** Error : Queue is full. \n" << endl; else if(rear==-1 && front==-1) { rear++; queue[rear]=item; front=rear; cout << "\n\n\t *** " << item << " is inserted into the Queue." << endl; } else { rear++; queue[rear]=item; cout << "\n\n\t *** " << item << " is inserted into the Queue." << endl; } cout << "\n\n\n\t\t Press any key to return to Menu " << endl; cin.get(); } void LinearQueue::Delete() { if(rear==-1 && front==-1) cout << "\n\n\n\t *** Error : Queue is empty. \n" << endl; else { cout << "\n\n\n\t *** " << queue[front] << " is deleted from the Queue." << endl; queue[front]=0; if(front==rear) front=rear=-1; else front++; } cout << "\n\n\n\t\t Press any key to return to Menu. " << endl; cin.get(); } void LinearQueue::print_queue() { if(front!=-1 && rear!=-1) { cout << "\n\n\n\n\n\t Values inserted into the Queue are : \n" << endl; for(int count=front;count<=rear;count++) cout << "\t Stack [" << count << "] = " << queue[count] << endl; } else cout << "\n\n\n\n\n\t *** Nothing to show. " << endl; cout << "\n\n\n\t\t Press any key to return to Menu. " << endl; cin.get(); } void LinearQueue::show_working() { char Key; do { system("CLS"); cout << setw(40) << " " << endl; cout << setw(53) << "***Linear ***** MAIN MENU ***** Queue*** " << endl; cout << setw(40) << " " << endl; cout << setw(49) << "Select one of the listed operation : " << endl; cout << setw(42) << "Press 'I' to Insert a value : " << endl; cout << setw(42) << "Press 'D' to Delete a value : " << endl; cout << setw(44) << "Press 'P' to Print the values : " << endl; cout << setw(31) << "Press 'E' to Exit: " << endl; Input: cout << setw(40) << " " << endl; cout << setw(39) << "Please Enter Your Choice : " << endl; Key = cin.get(); if(int(Key)==27 || Key=='e' || Key=='E') break; else if(Key=='i' || Key=='I') Insert( ); else if(Key=='d' || Key=='D') Delete( ); else if(Key=='p' || Key=='P') print_queue(); else goto Input; } while(1); } int main() { LinearQueue obj; obj.show_working(); return 0; }