线性结构:线性表(链表)、栈、队列、双向链表,C语言实现模板
本文为本人学习过程中整理的学习笔记,想顺带学英语所以用英文呈现。发现错误还烦请指正。欢迎交流。
未经同意,请勿转载。
文章目录
Linear Structure
Definition
Linear Data Structure is a finite sequence of data elements in the form of ( A 1 , A 2 , . . . , A n ) (A_1, A_2, ..., A_n) (A1,A2,...,An)
- Each element in the list has a position.
- All elements must have the same type.
- n n n is the length of the structure.
Lists
Linked-lists implementation
-
Properties
typedef int ListType; typedef struct _listnode{ ListType val; struct _listnode *next; } ListNode; typedef struct { ListNode *head_sentinel, *tail; int size; } _list, *List;
-
Constructor
List create_list(){ List lt = (List)malloc(sizeof(_list)); lt->head_sentinel = (ListNode*)calloc(1, sizeof(ListNode)); // head sentinel lt->tail = lt->head_sentinel; lt->size = 0; return lt; }
-
Destructor
void delete_list(List lt){ ListNode *to_del; ListNode *pos = lt->head_sentinel; while(pos){ to_del = pos;