链表和队列的非正式的抽象定义

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
posted @ 2020-07-09 00:38  诗和远方*  阅读(151)  评论(0编辑  收藏  举报