⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 list.c

📁 离散事件模拟程序
💻 C
字号:
// file: List.c

#include "list.h"
#include <malloc.h>

bool InitList(Linklist *L)
{
    L->head = L->tail = (evt_node *)malloc(sizeof(evt_node));
    if (!L->head)return false;
    L->head->next = 0;
    return true;
}

bool DestroyList(Linklist *L)
{
    while(L->head)
    {
        L->tail = L->head->next;
        free(L->head);
        L->head = L->tail;
    }
    return true;
}

bool ClearList(Linklist *L)
{
    DestroyList(L);
    return InitList(L);
}

// 已知head是头结点,将s所指结点插入在第一个结点之前
// 注意:可能会导致链表的tail值不准确
bool InsFirst(evt_node *head, evt_node *s)
{
    s->next = head->next;
    head->next = s;
    return true;
}

// 注意:可能会导致链表的tail值不准确
bool DesFirst(evt_node *head, elemtype *q)
{
    evt_node *p = head->next;
    head->next = p->next;
    *q = p->evtype;
    free(p);
    return true;
}

// 将s所指的一串结点链接在L的最后一个结点
bool Append(Linklist *L, evt_node *s)
{
    L->tail->next = s;
    while(L->tail->next)
    {
        L->tail = L->tail->next;
    }
    return true;
}

bool ListEmpty(Linklist L)
{
    return (L.tail == L.head);
}

int ListLength(Linklist L)
{
    return L.tail - L.head;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -