抽象数据类型 | ADT
Objects
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.
List
数组 | Array
链表 | LinkedList
单向链表
双向环形链表 | Doubly Linked Circular List
/应用/
多项式加减乘除法
typedef struct poly_node *poly_ptr;
struct poly_node {
int Coefficient ; /* assume coefficients are integers */
int Exponent;
poly_ptr Next ;
} ;
typedef poly_ptr a ; /* nodes sorted by exponent */
多链表 | Multilists
链表的游标实现 | Cursor Implementation
实现要点在于用结构体数组模拟链表,同时用一个freelist(freelist总以CursorSpace[0]为头)来记录还没使用的空间。
两个重要的操作——分配内存和释放内存
mallocp = CursorSpace[0].Next;
CursorSpace[0].Next = CursorSpace[p].Next;
free(p)CursorSpace[p].Next = CursorSpace[0].Next;
CursorSpace[0].Next = p;
/释放的空间总插入到freelist头结点后也即CursorSpace[0]后/
Stack
FILO(First In Last Out)
这里的指针实际上是pre指针,从尾部开始建立链表。
Push为插入结点,Pop为删除结点。
Queue
循环队列 | Circular Queue
队列已满,此时实际上还有一个空间。
队列为空,Front
指针指向[1]
。