KYSDK_SKIPLIST_DELETE(3)

NAME
kysdk_skiplist_delete - 删除key值对应的节点

SYNOPSIS
br

#include <skip_linklist.h>

  Functions

  int kysdk_skiplist_delete (kysdk_skiplist * list, int key)

删除key值对应的节点

Parameters
    list 需要操作的链表
    key 键

Returns
    int, 成功删除返回0，失败返回-1

Link with -lkydatastruct.

Detailed Description

接口的主要功能是删除key值对应的节点

EXAMPLES
    #include <skip_linklist.h>
    #include <stdlib.h>
    #include <time.h>
    #include <stdio.h>
    #include <unistd.h>
    #define ARRAY_SIZE    20
    int array[ARRAY_SIZE];
    int del_flag[ARRAY_SIZE] = {0};
    void print_list(kysdk_skiplist *list)
    {
        for (int i = list->max_levels - 1; i >= 0; i --)
        {
            kysdk_skiplist_node *curnode = list->children[i];
            printf("Level[%d]: ", i);
            while (curnode)
            {
                printf("%d->", curnode->key);
                curnode = curnode->next[i];
            }
            printf("NULL);
        }
    }
    int test_list_delete(kysdk_skiplist *list)
    {
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            if (random() % 2)
            {
                del_flag[i] = 1;
                kysdk_skiplist_delete(list, array[i]);
                printf("Deleted %d, array[i]);
            }
        }
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            if (del_flag[i] && kysdk_skiplist_search(list, array[i]).num != -1)
            {
                printf("Skiplist delete test failed.);
                return -1;
            }
        }
        printf("Skiplist order test pass.);
        return 0;
    }
    int main()
    {
        kysdk_skiplist *list = kysdk_create_skiplist();
        kysdk_skiplist_setmaxlevels(list, 5);

        srand(time(NULL));
        for (int i = 0; i < ARRAY_SIZE; i ++)
        {
            array[i] = i;
            kysdk_skiplist_insert(list, i, (kysdk_listdata)i);
            printf("%d has been insert., i);
            sleep(1);
        }

        print_list(list);
        int res = test_list_delete(list);
        print_list(list);
        kysdk_destroy_skiplist(list);
        return res;
    }

CONFORMING TO
These functions are as per the withdrawn POSIX.1e draft specification. The following functions are Linux extensions: kysdk_create_skiplist(), kysdk_destroy_skiplist(), kysdk_skiplist_setmaxlevels(), kysdk_skiplist_insert() and kysdk_skiplist_search().

SEE ALSO
kysdk_create_skiplist(3), kysdk_destroy_skiplist(3), kysdk_skiplist_setmaxlevels(3), kysdk_skiplist_insert(3) and kysdk_skiplist_search(3).

Author

Generated automatically by Doxygen for skip_linklist.h from the source code.