#include<iostream>
using namespace std;
struct Node{
int data;
Node *next;
};
class Queue_Linklist{
Node *front;
Node *rear;
public:
Queue_Linklist(){
rear = front = NULL;
}
void insert(int num){
Node *temp = new Node;
temp->data = num;
temp->next = NULL;
if(rear == NULL){
rear = temp;
front = temp;
}
else{
rear->next = temp;
rear = temp;
}
}
int remove(){
int copy = front->data;
Node *del = front;
front = front->next;
if(front == NULL){
rear = NULL;
}
delete del;
return copy;
}
void Display()
{
Node *temp = front;
cout<<"DATA IN QUEUE IS: ";
while(temp != NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
}
};
int main()
{
Queue_Linklist Q;
char choice;
do{
int input;
cout<<"1) TO INSERT NUMBER: \n";
cout<<"2) TO REMOVE NUMBER: \n";
cout<<"33) TO DISPLAY QUEUE: ";
cin>>input;
system("cls");
switch(input){
case 1:{
int num;
cout<<"ENTER NUMBER: ";
cin>>num;
Q.insert(num);
break;
}
case 2:{
cout<<"REMOVED NUMBER IS: "<<Q.remove()<<endl;
break;
}
case 3:{
Q.Display();
break;
}
default:{
cout<<"EROR 404: "<<endl;
break;
}
}
cout<<"\nDO YOU WANT TO CONT...(Y/N)...";
cin>>choice;
system("cls");
}while(choice == 'y');
return 0;
}
-
Infix to Postfix Converstion
* C++ implementation to convert infix expression to postfix*
-
DOUBLY QUEUE IMPLEMENTATION C++
Double Queue Implemention Guide.
-
Data Structures in JavaScript
As business logic moves from the back to the front, expertise in front-end engineering becomes even more important. As for front-end engineers, we rely on viable libraries to be effective.
-
Coding Problem To Solve Exercise 1
here is Some Coding Problem For Beginners To Boost up their Confidence and to get grip on programming. This problem is for beginner levels for their brainstorming.
-
Coding Problem To Solve Exercise 2
here is Some Coding Problem For Beginners To Boost up their Confidence and to get grip on programming. This problem is for beginner levels for their brainstorming.
-
Coding Problem To Solve Exercise 3
* here is Some Coding Problem For Beginners To Boost up their Confidence and to get grip on programming. This problem is for beginner levels for their brainstorming.*
Queue Using Linked List c++
Queue implementation in C++
//Queue implementation in C++
#include<iostream>
using namespace std;
class Queue {
int item[5];
int front;
int rear;
public:
Queue() { //Constructor....
front = 0;
rear = -1;
}
void insert(int x) { // INSERTION FUNCTION TO INSERT VALUES IN QUEUE....
item[++rear] = x;
}
bool isempty() {
if (front>rear)
return true;
return false;
}
void apinsert(int x) { // ORDERING OF DATA IN QUEUE IN ASSENDING ORDER....
if (isempty()) {
insert(x);
}
else if (x >= item[rear])
{
insert(x);
}
else
{
Queue q2;
while (!isempty()) {
int t = remove();
if (x<t) {
q2.insert(x);
q2.insert(t);
break;
}
else
{
q2.insert(t);
}
}
while (!isempty())
q2.insert(remove());
front = 0;
rear = -1;
while (!q2.isempty()) {
insert(q2.remove());
}
}
}
int remove()
{
return item[front++];
}
void dislpay()
{
for (int k = 4; k>rear; k--)
cout << "\nEmpty";
for (int i = rear; i >= front; i--)
cout << endl << item[i];
for (int j = (front - 1); j >= 0; j--)
cout << "\nEmpty";
}
bool isfull()
{
if (rear >= 4)
return true;
return false;
}
};
int main() // MAIN DRIVER....
{
Queue q1;
char repeat = 'y';
do {
int input;
cout << "1) Press '1' to insert: " << endl;
cout << "2) Press '2' to remove: " << endl;
cout << "3) Press '3' to Display: " << endl;
cin >> input;
system("cls"); //STANDARD LIBARAY HEADER FILE (TO CLEAR SCREEN)
switch (input) {
case 1: {
int num;
cout << "Enter Number: ";
cin >> num;
system("cls");
q1.apinsert(num);
break;
}
case 2: {
if (q1.isempty())cout << "\nThe queue is already empty";
else
cout << "\nThe removed value is:" << q1.remove();
break;
}
case 3: {
q1.dislpay();
break;
}
default:
cout << "Error 404: ";
}
cout << "\nRepeat: y/n..";
cin >> repeat;
system("cls");
} while (repeat == 'y');
return 0;
}