search in Queue C++
Здравейте! Ще помоля някой , ако може да ми помогне. Трябва ми да потърся елемент в масива на опашката, да го намеря, да бъде изтрит и добавен в края. Как?!? Със стандартното търсене в масив не се получава. Моля...
Пример:
10, 20, 30, 40,50,
въведете число:
cin>> 20;
10,30,40,50,20
#include <iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
node *next;
};
class queue
{
node *rear, *front;
public:
queue()
{
rear = NULL;front = NULL;
}
void qinsert();
void qdelete();
void qdisplay();
~queue();
};
void queue::qinsert()
{
for (int i = 0;i < 5;i++) {
node *temp;
temp = new node;
cout << "\nData :";
cin >> temp->data;
temp->next = NULL;
if (rear == NULL)
{
rear = temp;
front = temp;
}
else
{
rear->next = temp;
rear = temp;
}
}
}
void queue::qdelete()
{
if (front != NULL)
{
node *temp = front;
cout << "\nDeleted: " << front->data << endl;
front = front->next;
delete temp;
temp->data;
temp->next = NULL;
if (rear == NULL)
{
rear = temp;
front = temp;
}
if (front == NULL)
{
rear = NULL;
}
else
{
rear->next = temp;
rear = temp;
}
}
else
cout << "\nQueue Empty..";
}
void queue::qdisplay()
{
node *temp = front;
while (temp != NULL)
{
cout << temp->data << endl;
temp = temp->next;
}
}
queue::~queue()
{
while (front != NULL)
{
node *temp = front;
front = front->next;
delete temp;
}
}
int main()
{
queue obj;
cout << "\n Insert five numbers ";
obj.qinsert();
obj.qdelete();
obj.qdisplay();
return 0;
}