1.LAB要求
完成单链表的操作,包括
1. 新建空链表
2. 释放列表
3. 头部插入元素
4. 尾部插入元素,O(1)时间
5. 删除头部元素
6. 获取size,O(1)时间
7. 翻转,不允许分配额外的空间,不能使用递归
/*
Create empty queue.
Return NULL if could not allocate space.
*/
queue_t *q_new();
/*
Free all storage used by queue.
No effect if q is NULL
*/
void q_free(queue_t *q);
/*
Attempt to insert element at head of queue.
Return true if successful.
Return false if q is NULL or could not allocate space.
*/
bool q_insert_head(queue_t *q, int v);
/*
Attempt to insert element at tail of queue.
Return true if successful.
Return false if q is NULL or could not allocate space.
*/

本文详细介绍了如何完成CSAPP实验中关于单链表的各项操作,包括创建空链表、释放链表、头部插入和删除、尾部插入、获取链表长度以及不使用额外空间翻转链表。实现中关键在于维护一个指向链表尾部的指针,以确保大部分操作能在O(1)时间内完成。
最低0.47元/天 解锁文章
2519

被折叠的 条评论
为什么被折叠?



