复习内容
科目 | 内容 | 补充 | 时间 |
---|---|---|---|
数学 | 积分概念性质几何意义、不定积分的计算(真题) | P133 | |
数据结构 | 链栈 |
链队基本操作
//链队
#include <malloc.h>
#include <stddef.h>
#include <stdio.h>
typedef struct LinkNode
{
int data; //数据
struct LinkNode *next;
} LinkNode;
typedef struct LinkQueue
{
LinkNode *front, *rear; //队列的队头队尾
} LinkQueue;
//初始化
void InitQueue(LinkQueue &Q)
{
Q.front = (LinkNode *)malloc(sizeof(LinkNode));
Q.front->next = NULL;
}
//判断队空
bool IsEmpty(LinkQueue Q)
{
if (Q.front == Q.rear)
return true;
else
return false;
}
//入队
void EnQueue(LinkQueue &Q, int x)
{
LinkNode *s = (LinkNode *)malloc(sizeof(LinkNode));
s->data = x;
s->next = NULL;
Q.rear->next = s;
Q.rear = s;
}
//出队
bool DeQueue(LinkQueue &Q, int &x)
{
if (Q.rear == Q.front)
return false;
LinkNode *p = Q.front->next;
x = p->data;
Q.front->next = p->next;
if (Q.rear == p)//若p正好是最后一个节点
Q.rear = Q.front;//表尾指针指向头结点
free(p);
return true;
}