zoukankan      html  css  js  c++  java
  • 链表和队列的非正式的抽象定义

    1.类型名:简单链表

    2.类型属性:可以存储一系列项

    3.类型操作:初始化链表为空

                                 确定链表为空

                                 确定链表已满

                                 确定链表中的项数

                                 在链表末尾添加项

                                 遍历链表,处理链表中的项

                                 清空链表

    list.h的组织形式(代码):

    #ifndef LIST_H_
    #define LIST_H_
    #include<stdbool.h>
    #define TSIZE 45
    struct film
    {
      char title[TSIZE];
      int rating;
    };
    typedef struct film Item;
    typedef struct node
    {
      Item item;
      struct node * next;
    }Node,* List;
    void InitalizeList(List * plist);
    bool ListIsEmpty(const List *plist);
    bool ListIsFull(const List *plist);
    unsigned int ListItemCount(const List *plist);
    bool AddItem(Item item,List * plist);
    void Traverse(const List *plist,void(*pfun)(Item item));
    void EmptyTheList(List * plist);
    #endif

    1.类型名:队列

    2.类型属性:可以存储一系列的项

    3.类型操作:初始化队列为空

                                 确定队列为空

                                 确定队列已满

                                 确定队列中的项数

                                 在队列末尾添加项

                                 在队列开头删除或者恢复项

                                 清空队列

    queue.h组织形式:

    /*queue.h -- Queue的接口*/
    #ifndef _QUEUE_H_
    #define _QUEUE_H_
    #include <stdio.h>
    #include <stdbool.h>
    //在这里插入Item类型的定义,例如typedef int Item;//用于use_q.c;
    typedef int Item;
    #define MAXQUEUE 10

    typedef struct node
    {
      Item item;
      struct node * next;
    }Node;
    typedef struct Queue
    {
      Node * front;
      Node * rear;
      int items;
    }Queue;
    void InitalizeListQueue(Queue * pq);
    bool QueueIsFull(const Queue * pq);
    bool QueueIsEmpty(const Queue *pq);
    int QueueItemCount(const Queue * pq);
    bool EnQueue(Item item,Queue * pq);
    bool DeQueue(Item *pitem,Queue *pq);
    void EmptyTheQueue(Queue *pq);
    #endif
  • 相关阅读:
    截取字符串的值
    Tomcat发布项目方法
    struts标签
    正则表达式范例
    树的操作方法
    树结点动态帮定事件
    I/O 流和对象序列化
    Word中的字体大小
    script实现的日期表示
    JavaScript弹出窗口技巧
  • 原文地址:https://www.cnblogs.com/shiheyuanfang/p/13270195.html
Copyright © 2011-2022 走看看