1. 插入
void insert ( LinkList* list, int pos, LinkNode* data)
{
if ( ! list || ! data)
return ;
if ( pos < 0 || pos > list-> size)
return ;
LinkNode* curNode = & ( list-> head) ;
for ( int i = 0 ; i < pos; ++ i) {
curNode = curNode-> next;
}
data-> next = curNode-> next;
curNode-> next = data;
list-> size++ ;
}
2. 代码实现
# pragma once
struct LinkNode
{
LinkNode* next;
} ;
struct LinkList
{
LinkNode head;
int size = 0 ;
} ;
LinkList* init ( )
{
LinkList* list = new LinkList ( ) ;
list-> head. next = nullptr ;
list-> size = 0 ;
return list;
}
void insert ( LinkList* list, int pos, LinkNode* data)
{
if ( ! list || ! data)
return ;
if ( pos < 0 || pos > list-> size)
return ;
LinkNode* curNode = & ( list-> head) ;
for ( int i = 0 ; i < pos; ++ i) {
curNode = curNode-> next;
}
data-> next = curNode-> next;
curNode-> next = data;
list-> size++ ;
}
int find ( LinkList* list, LinkNode* node) ;
void remove ( LinkList* list, int pos) ;
int size ( LinkList* list) ;
void ddstroy ( LinkList* list) ;