HangDoi
#include<iostream>
#include<stdio.h>
using namespace std;
class Queue
{
private:
enum{size=32};
int a[size];
int F, R;
public:
Queue();
void insert(int x);
int remove();
bool isEmpty();
};
int main()
{
cout<<endl;
return 0;
}
Queue::Queue():F(-1){}
void Queue::insert(int x)
{
if(F==0 && R == size-1 || F == R+1)
{
cout<<"Hang doi day!";
return;
}
if(R==-1) F=R=0;
else if(R==size-1) R=0;
else R++;
a[R] = x;
}
int Queue::remove()
{
if(F==-1)
{
cout<<"hang doi rong!";
return 1;
}
int tg = a[F];
if(F==R) F=R=-1;
else if(F == size-1) F=0;
else F++;
return tg;
}
bool Queue::isEmpty()
{
return F==-1;
}
// hang doi phan tan
#include<iostream>
#include<stdio.h>
using namespace std;
class Queue
{
private:
struct node
{
int infor;
node *link;
}*F, *R;
public:
Queue();
~Queue();
void insert(int x);
int remove();
bool isEmpty();
};
int main()
{
cout<<endl;
return 0;
}
Queue::Queue():F(NULL),R(NULL){}
Queue::~Queue()
{
while(F)
{
node *P = F;
F = F->link;
delete P;
}
}
void Queue::insert(int x)
{
node *N = new node;
N->infor = x;
N->link = NULL;
if(R==NULL) R = F = N;
else R->link = N;
R = N;
}
int Queue::remove()
{
if(F==NULL)
{
cout<<"Hang doi rong!";
return 1;
}
int tg = F->infor;
node *P = F;
if(F==R) F=R=NULL;
else F=F->link;
delete P;
return tg;
}
bool Queue::isEmpty()
{
return F==NULL;
}
Last updated