数据结构域算法设计-第3章 堆栈与队列(II) 课件

上传人:woxinch****an2018 文档编号:45279992 上传时间:2018-06-15 格式:PPT 页数:25 大小:596.50KB
返回 下载 相关 举报
数据结构域算法设计-第3章 堆栈与队列(II) 课件_第1页
第1页 / 共25页
数据结构域算法设计-第3章 堆栈与队列(II) 课件_第2页
第2页 / 共25页
数据结构域算法设计-第3章 堆栈与队列(II) 课件_第3页
第3页 / 共25页
数据结构域算法设计-第3章 堆栈与队列(II) 课件_第4页
第4页 / 共25页
数据结构域算法设计-第3章 堆栈与队列(II) 课件_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《数据结构域算法设计-第3章 堆栈与队列(II) 课件》由会员分享,可在线阅读,更多相关《数据结构域算法设计-第3章 堆栈与队列(II) 课件(25页珍藏版)》请在金锄头文库上搜索。

1、第三章 堆栈与队列 (II)西安电子科技大学理学院 Data Structure1Chapter 3: Stack struct QueueNode ElemType data; QueueNode *next; ; struct ListQueue QueueNode *front; QueueNode *rear; int count; ;4frontrearcountData Structure6Chapter 3: Stack struct SqQueue QElemType baseMAXQSIZE; int front, rear; ; void InitQueue(SqQueue

2、 *q) q-front = q-rear = 0; Status QueueFull(SqQueue *q) return (q-rear+1)%MAXQSIZE = q-front); Status QueueEmpty(SqQueue *q) return (q-front = q-rear); int QueueLength(SqQueue *q) return (q-rear - q-front + MAXQSIZE)%MAXQSIZE; Status EnQueue(SqQueue *q, QElemType e) if (QueueFull(q) return FALSE; el

3、se q-baseq-rear = e; q-rear = (q-rear+1)%MAXQSIZE; return TRUE; Status DeQueue(SqQueue *q, QElemType *e) if (QueueEmpty(q) return FALSE; else *e = q-baseq-front; q-front = (q-front+1)%MAXQSIZE; return TRUE; Data Structure15Chapter 3: Stack P(h); Data Structure23Chapter 3: Stack P(q-mutex); QueueNode

4、 *qn = (QueueNode *) malloc(sizeof(QueueNode); qn-m = c; qn-next = NULL; q-count +; if (q-front = NULL) q-front = q-rear = qn; else q-rear-next = qn; q-rear = qn; V(q-mutex); V(q-sem); return 1; int DeQueue(Queue *q, Client *c) P(q-sem); if (q-front = NULL) return 0;P(q-mutex); *c = q-front-m; Queue

5、Node *t = q-front; q-front = q-front-next; q-count -; if (q-count = 0) q-rear = NULL; free(t); V(q-mutex); return 1; void InitQueue(Queue *q) q-front = q-rear = NULL; q-count = 0; q-sem = CreateSemaphore(0, 0, 100, 0); q-mutex = CreateSemaphore(0, 1, 1, 0); Data Structure24Chapter 3: Stack & QueueCl

6、ient: 0 is arrival, wait at queue 2Server2: client 0. Client: 1 is arrival, wait at queue 2 Client: 2 is arrival, wait at queue 0Server0: client 2.Server2: client 0 leaveServer2: client 1. Client: 3 is arrival, wait at queue 2 Client: 4 is arrival, wait at queue 0 Client: 5 is arrival, wait at queue

7、 1Server1: client 5. Client: 6 is arrival, wait at queue 0Server2: client 1 leaveServer2: client 3. Client: 7 is arrival, wait at queue 2 Client: 8 is arrival, wait at queue 1 Client: 9 is arrival, wait at queue 2Server0: client 2 leaveServer0: client 4. Client: 10 is arrival, wait at queue 0Server2

8、: client 3 leaveServer2: client 7. Client: 11 is arrival, wait at queue 0Server1: client 5 leaveServer1: client 8. Client: 12 is arrival, wait at queue 1Server2: client 7 leaveServer2: client 9.Server0: client 4 leaveServer0: client 6. Client: 13 is arrival, wait at queue 2 Client: 14 is arrival, wait at queue 0 Client: 15 is arrival, wait at queue 0 Client: 16 is arrival, wait at queue 1 Client: 17 is arrival, wait at queue 1Data Structure25Chapter 3: Stack & Queue

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号