Ch03-表栈队列预案.ppt

表栈队列 高文宇 gwyy@163.com §1 抽象数据类型 定义1(ADT): Data Type = { Objects } ? { Operations } 示例1: int = { 0, ?1, ?2, ? ? ?, INT_MAX, INT_MIN } ? { ?, ?, ?, ?, ?, ? ? ? } 在面向对象程序设计中,类(对象)就可以视为ADT。 §2 表ADT Objects: ( item0, item1, ??? , itemN?1 ) Operations: ? Finding the length, N, of a list. ? Printing all the items in a list. ? Making an empty list. ? Finding the k-th item from a list, 0 ? k N. ? Inserting a new item after the k-th item of a list, 0 ? k N. ? Deleting an item from a list. ? Finding next of the current item from a list. ? Finding previous of the current item from a list. 表的简单数组实现 链表 链表的插入 链表的删除 双向循环链表 表的应用—多项式ADT Objects : P ( x ) = a1 x e1 + ??? + an x en ; a set of ordered pairs of ei , ai where ai is the coefficient and ei is the exponent. ei are nonnegative integers. Operations: ? Finding degree, max { ei }, of a polynomial. ? Addition of two polynomials. ? Subtraction between two polynomials. ? Multiplication of two polynomials. ? Differentiation of a polynomial. 多项式的数组实现 多项式的链式实现 表的应用—多重表 表的应用—多重表 §3 栈ADT 栈(Stack):后进先出(LIFO)。 Objects: A finite ordered list with zero or more elements. Operations: ? Int IsEmpty( Stack S ); ? Stack CreateStack( ); ? DisposeStack( Stack S ); ? MakeEmpty( Stack S ); ? Push( ElementType X, Stack S ); ? ElementType Top( Stack S ); ? Pop( Stack S ); 栈的链表实现 栈的数组实现 栈的应用—平衡符号 栈的应用—后缀表达式 后缀表达式的计算 中缀表达式转换成后缀表达式 后缀表达式的计算 中缀转后缀 中缀转后缀 中缀转后缀 栈的应用—函数调用 §4 队列ADT 队列(Queue):先进先出(FIFO)。 Objects: A finite ordered list with zero or more elements. Operations: ? int IsEmpty( Queue Q ); ? Queue CreateQueue( ); ? DisposeQueue( Queue Q ); ? MakeEmpty( Queue Q ); ? Enqueue( ElementType X, Queue Q ); ? ElementType Front( Queue Q ); ? Dequeue( Queue Q ); 队列的实现 队列的应用 计算机作业提交 售票窗口排队 计算机网络 排队论(Queuing theory):用概率方法计算排队的等待时间,队列长度等。 作业 看程序: list.c,list.h—链表ADT的实现 stackar.c,stackar.h—栈的数组实现 stackli.c,stackli.h—栈的链式实现 queue.c,queue.h—队列的数组实现 再见 再见 * array[ i ] = itemi ? MaxSize has to be estimated. Address Content array+i ite

文档评论(0)

1亿VIP精品文档

相关文档