?? 5-11.c
字號:
#include "stdio.h"
typedef char datatype;
typedef struct node{
datatype data;
struct node *next;
} position;
typedef struct queue{
position *front;
position *rear;
}queuetype;
//使隊列為空:
void MackNull(queuetype * q)
{
q->rear=q->front;
while(q->front!=NULL){
q->front=q->front->next;
free(q->rear);/*釋放空間*/
q->rear=q->front;
}
q->front=(position*)malloc(sizeof(position*));
q->front->next=NULL;
q->rear=q->front;
}
// 取隊列的隊頭元素:
datatype Front(queuetype * q)
{
if(Empty(q))
printf("'The queue is empty!");
else
return(q->front->next->data);
}
//刪除隊列頭元素:
void dequeue(queuetype * q)
{
position* p;
if(Empty(q))
printf("'The queue is empty!");
else{
p=q->front;
q->front=q->front->next;
free(p);
}
}
// 在隊列中加入新元素:
void Enqueue(datatype x,queuetype * q)
{
position* p;
p=(position*)malloc(sizeof(position*));
p->data=x;
p->next=NULL;
q->rear->next=p;
q->rear=p;
}
//判斷是否為空隊列:
int Empty(queuetype * q)
{
return (q->front==q->rear);
}
void main()
{
queuetype * m_q;
char m_top;
if(!Empty(m_q))
{
m_top=Front(m_q);
dequeue(m_q);
}
else
Enqueue('c',m_q);
MackNull(m_q);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -