首页 > 其他 > 详细

6-6 带头结点的链式表操作集 (20 分)

时间:2019-09-04 12:21:47      阅读:1097      评论:0      收藏:0      [点我收藏+]

题目地址:https://pintia.cn/problem-sets/15/problems/729

头节点创建但并不储存信息,操作与普通链式表基本相同

技术分享图片
List MakeEmpty() {
    List L = (List)malloc(sizeof(struct LNode));
    L ->Next = NULL;
    return L;
}

Position Find(List L, ElementType X) {
    List q = L;
    while(q) {
        if(q->Data == X) return q;
        q = q->Next;
    }
    return ERROR;
}

bool Insert(List L, ElementType X, Position P) {
    if(P == L->Next) {
        List p = (List)malloc(sizeof(struct LNode));
        p->Data = X;
        p->Next = L->Next;
        L->Next = p;
        return true;
    }

    List p = L;
    while(p) {
        if(p->Next == P) {
            List q = (List)malloc(sizeof(struct LNode));
            q->Data = X;
            q->Next = P;
            p->Next = q;
            return true;
        }
        p = p->Next;
    }
    printf("Wrong Position for Insertion\n");
    return false;
}

bool Delete(List L, Position P) {
    List q = L;
    while(q) {
        if(q->Next == P) {
            q->Next = P->Next;
            return true;
        }
        q = q->Next;
    }
    printf("Wrong Position for Deletion\n");
    return false;
}
View Code

 

6-6 带头结点的链式表操作集 (20 分)

原文:https://www.cnblogs.com/mile-star/p/11458151.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!