VxWorks下使用双向链表lstLib的小例子

本文介绍了如何使用lstLib模块初始化列表、添加节点、获取节点信息及释放资源的基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdlib.h>
#include <stdio.h>
#include <lstLib.h>


typedef struct _Queue
{
 NODE * next;
 NODE * prev;
 int age;
 char name[255];


} QUEUE;


LIST list;


void TestList()
{
    QUEUE *p;
    int i;


    lstLibInit();
    lstInit(&list);
    for(i = 0; i < 10; i++)
    {
        p = malloc(sizeof(QUEUE));
        if(p) 
        {
            p->age = i * 5;
            sprintf(p->name, "person %d", i);
            lstAdd(&list, (NODE*)p);
        }
    }


    for(i = 0; i < 10; i++)
    {
        p = (QUEUE*)lstGet(&list);  //执行该语句后,该节点会自动被删除
        if(p)
        {
            printf("name = %s, age = %d\n", p->name, p->age);
            free(p);
        }
    }


    lstFree(&list);

}


lstLibInit( ) - initializes lstLib module
lstInit( ) - initialize a list descriptor
lstAdd( ) - add a node to the end of a list
lstConcat( ) - concatenate two lists
lstCount( ) - report the number of nodes in a list
lstDelete( ) - delete a specified node from a list
lstExtract( ) - extract a sublist from a list
lstFirst( ) - find first node in list
lstGet( ) - delete and return the first node from a list
lstInsert( ) - insert a node in a list after a specified node
lstLast( ) - find the last node in a list
lstNext( ) - find the next node in a list
lstNth( ) - find the Nth node in a list
lstPrevious( ) - find the previous node in a list
lstNStep( ) - find a list node nStep steps away from a specified node
lstFind( ) - find a node in a list
lstFree( ) - free up a list


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值