首页 > 其他分享 >3任务创建-列表项插入函数&列表项末尾插入函数

3任务创建-列表项插入函数&列表项末尾插入函数

时间:2022-12-28 21:33:40浏览次数:40  
标签:函数 pxNewListItem 列表 插入 pxNext pxList pxPrevious

1.列表项插入函数

 通过列表项项值xItemValue比对,查找插入位置

 1 void vListInsert( List_t * const pxList, ListItem_t * const pxNewListItem )
 2 {
 3     ListItem_t pxIterator;                            // 新建临时列表项,用于遍历列表
 4     const TickType_t xValueOfInsertion = pxNewListItem->xItemValue;    // 获取要插入列表项的值
 5     if ( xValueOfInsertion == portMAX_DELAY )        // 要插入列表项项值判断位置,是否在列表最后
 6     {
 7         pxIterator = pxList->xListEnd.pxPrevious;    // 将列表最后的前一个值改变
 8     }
 9     else
10     {
11         for (   pxIterator = ( ListItem_t * ) &( pxList->xListEnd );// 索引从链表最后开始往前索引
12                 pxIterator->pxNext->xItemValue <= xValueOfInsertion;// 通过next索引,与要插入列表项值比较
13                 pxIterator = pxIterator->pxNext )                    // 移动next指针进行索引
14         {
15         
16         }
17     }
18     pxNewListItem->pxNext = pxIterator->pxNext;            // 改变要插入列表项的 next 指针
19     pxNewListItem->pxNext->pxPrevious = pxNewListItem;     // 改变要插入列表项的 prev 指针
20     pxNewListItem->pxPrevious = pxIterator;                
21     pxIterator->pxNext = pxNewListItem;
22 
23     pxNewListItem->pvContainer = ( void * ) pxList;        // 通过pvContainer标记列表项属于哪个列表
24     ( pxList->uxNumberOfItems )++;                         // 列表的列表项数目自增
25 }

实现过程

 

2.列表项末尾插入函数

 

 1 void vListInsertEnd( List_t * const pxList, ListItem_t * const pxNewListItem )  
 2 {  
 3 ListItem_t* const pxIndex = pxList->pxIndex;  
 4    
 5          /*检查列表和列表项数据的完整性,仅当configASSERT()定义时有效。*/  
 6          listTEST_LIST_INTEGRITY( pxList );  
 7          listTEST_LIST_ITEM_INTEGRITY(pxNewListItem );  
 8    
 9          /*向列表中插入新的列表项*/  
10          pxNewListItem->pxNext = pxIndex;  
11          pxNewListItem->pxPrevious =pxIndex->pxPrevious;  
12    
13          mtCOVERAGE_TEST_DELAY();  
14    
15          pxIndex->pxPrevious->pxNext =pxNewListItem;  
16          pxIndex->pxPrevious = pxNewListItem;  
17    
18          pxNewListItem->pvContainer = ( void* ) pxList;  
19    
20          ( pxList->uxNumberOfItems )++;  
21 }  

实现过程

 

标签:函数,pxNewListItem,列表,插入,pxNext,pxList,pxPrevious
From: https://www.cnblogs.com/CC-C/p/17011295.html

相关文章