数据结构---链表队
来源:互联网 发布:sql 2008 sa 密码 编辑:程序博客网 时间:2024/06/06 09:37
队结构体定义:
typedef int datatype;typedef struct node{datatype data;struct node *next;}Queue;//链队结点类型
主函数内队伍的定义:
LQueue *head;head=InitQueue();
队伍头尾封装:
typedef struct {Queue *rear;Queue *front;}LQueue;//头尾指针封装在一起的链队
空队的初始化及建立:LQueue *InitQueue()//创建一个带头结点的空队 {LQueue *q;Queue *p; q=(LQueue *)malloc(sizeof(LQueue));//申请头尾指针结点p=(Queue *)malloc(sizeof(Queue));//申请链队头结点p->next=NULL,q->front=q->rear=p;return q;}
入队:void in_LQueue(LQueue *q,datatype x)//入队 {Queue *p;p=(Queue *)malloc(sizeof(Queue));printf("%d入队\n",x);p->data=x;p->next=NULL;q->rear->next=p;q->rear=p;}
判断队伍空则真,否则为假:
bool empty_LQueue(LQueue *q){if(q->rear==q->front){printf("队空!\n"); return true ;}return false;}
出队:
int out_LQueue(LQueue *q,datatype *x){Queue *p;if(empty_LQueue(q))return 0;p=q->front->next;q->front->next=p->next;*x=p->data;free(p);if(q->front->next==NULL)q->rear=q->front;//只有一个元素时,出队后队空,修改队尾指针return true; }
0 0
- 数据结构---链表队
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- 数据结构
- intellij idea的使用
- 【Shell】-- 入门笔记(2):流程控制,重定向及文件包含
- volatile
- 常见对象-把数组拼接成指定格式的字符串案例
- 在servlet中创建和应用session
- 数据结构---链表队
- 仅仅作为计划提醒
- 洛谷OJ
- c++操作符重载实现
- SAP GUI 750全新风采
- JavaScript中运算符的优先级
- 《RDF Graph Partitions: a Brief Survey》——笔记
- 未来物联网全栈开发 --JavaScript or Python?
- Construct Binary Tree from Inorder and Postorder Traversal