a=1,b=2,c=a+b
时间: 2024-05-23 10:15:38 浏览: 13
当您前面跟我说了什么时,我听到了一个笑话:'Why did the cookie go to the doctor? Because he felt crummy.'
关于队列操作的问题,代码如下:
#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 10
typedef struct{
int data[MAXSIZE];
int front;
int rear;
}Queue;
void InitQueue(Queue *Q){
Q->front = Q->rear = 0;
}
int QueueEmpty(Queue *Q){
if(Q->front == Q->rear){
return 1;
}
return 0;
}
int QueueFull(Queue *Q){
if((Q->rear+1)%MAXSIZE == Q->front){
return 1;
}
return 0;
}
int EnQueue(Queue *Q, int x){
if(QueueFull(Q)){
return 0;
}
Q->data[Q->rear] = x;
Q->rear = (Q->rear+1)%MAXSIZE;
return 1;
}
int DeQueue(Queue *Q, int n){
if(QueueEmpty(Q)){
return 0;
}
if(n > Q->rear - Q->front){
return 0;
}
int i;
for(i = 0; i < n; i++){
printf("%d ", Q->data[Q->front]);
Q->front = (Q->front+1)%MAXSIZE;
}
printf("\n");
return 1;
}
int GetHead(Queue *Q){
if(QueueEmpty(Q)){
printf("队列为空\n");
return 0;
}
printf("%d\n", Q->data[Q->front]);
return 1;
}
int main(){
Queue Q;
InitQueue(&Q);
int i, x;
for(i = 0; i < 10; i++){
x = rand()%100;
EnQueue(&Q, x);
}
printf("入队成功,队列数据为:\n");
while(!QueueEmpty(&Q)){
GetHead(&Q);
DeQueue(&Q, 1);
}
printf("请输入要出队的元素个数:\n");
int n;
scanf("%d", &n);
if(DeQueue(&Q, n)){
printf("出队成功,队列数据为:\n");
while(!QueueEmpty(&Q)){
GetHead(&Q);
DeQueue(&Q, 1);
}
}
else{
printf("出队失败\n");
}
return 0;
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)