mọi ngừoi giúp mìh bài này vs..sao xuất mãi ko dc z..
sử dụng các thao tác trên hàng đợi để xuất ra 1 mảng số nguyên;
đây là code của mình:
Mã:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct queue
{
int n, front, rear;
int *list;
};
void init(queue &q)
{
q.list= new int[q.n];
q.front=q.rear=0;
}
void nhap(queue &q)
{
printf("
Nhap mang so nguyen
");
for(int i=0;i<q.n;i++)
{
scanf("%d",&q.list[i]);
}
}
int isempty(queue q)
{
if(q.front==q.rear==0)
return 1;
if(q.front==q.rear)
return 1;
return 0;
}
int isfull(queue q)
{
if(q.front==0&&q.rear==q.n-1)
return 1;
if(q.front==q.rear)
return 1;
return 0;
}
void enqueue(queue &q, int &x)//them 1 phan tu vao cuoi queue
{
if(isfull(q)==0)
{
q.list[q.rear]=x;
q.rear++;
}
if(q.rear==q.n)
q.rear=0;
}
int dequeue(queue &q)//trich', huy phan tu o dau hang doi
{
int x;
if(isempty(q)==0)
{
x=q.list[q.front];
q.front++;
}
if(q.front==q.n)
q.front=0;
return x;
}
int main()
{
queue q;
int n, x;
printf("
Nhap n");
scanf("%d",&q.n);
init(q);
nhap(q);
for(int i=0;i<q.n;i++)
{
enqueue(q,q.list[i]);
}
for(int i=0;i<q.n;i++)
printf("
%d",dequeue(q));
}
View more random threads:
[/b] Tại Lương Sơn TV bạn sở hữu thể xem truyền hình trực tiếp bóng đá hôm nay các giải đấu to trong và ngoài nước. Lương Sơn TV ko chỉ đem lại những trận chiến mãn nhãn sở hữu chất lượng hình ảnh...
Các giải đấu không thể bỏ lỡ tại...