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
  • 相关阅读:
    深入理解并发编程 -- 多线程(一)
    使用Mybatis实现动态SQL(二)
    Java设计模式
    使用Mybatis实现动态SQL(一)
    Java
    Java安全(权限)框架
    List-LinkedList、set集合基础增强底层源码分析
    hadoop3.1.0 window win7 基础环境搭建
    springmvc传递有特殊字符的路径参数
    jhipster(springboot+datatable+jpa)后台分页,总结
  • 原文地址:https://www.cnblogs.com/shiheyuanfang/p/13270195.html
Copyright © 2011-2022 走看看