【DSA_Fall2020】1. Linear Structure (Templates in C)

本文介绍了线性数据结构的概念,包括链表、栈、队列和双向链表的C语言实现模板。链表的插入和追加操作均为常数时间复杂度,而按值删除则为线性时间复杂度。栈遵循先进后出(FIFO)原则,使用链表或数组实现,插入和移除操作均为常数时间。队列遵循先进先出(FILO)原则,链表实现时,入队和出队在有尾指针的情况下为常数时间,数组实现时,维护额外空间以优化操作。
摘要由CSDN通过智能技术生成

线性结构:线性表(链表)、栈、队列、双向链表,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;
         
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值