Hello!
Now the program make:
Insert 5 numbers:
5,10,15,20,25
disp:
delete: 5
display:
10,15,20,25,5
How to make?
Example
Insert 5 numbers:
cin >> ;
display:10,20,30,40,50
search for number:
cin>> 20;
display: 10,30,40,50,20????
Please help !
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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include<conio.h>
#include<stdlib.h>
#define siz 5
using namespace std;
struct node
{
int data;
node *next;
};
class queue
{int a [siz];
node *rear, *front;
public:
queue()
{
rear = NULL;front = NULL;
}
void qinsert();
void qdelete();
void qdisplay();
~queue();
};
void queue::qinsert()
{
for (int i = 0;i < siz;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;
}
|
Last edited on