typedef struct node
{
int data;
struct node *next;
}Node;
/*链表的插入(在指定位置之前插入)*/
void before_insert(Node *head, int position, int value)
{
Node *p = head;
Node *q = NULL;
int i = 0;
while(p && i++ < position - 1)
{
p = p->next;
}
q = (Node *)malloc(sizeof(Node));
q->data = value;
q->next = p->next;
p->next = q;
}
/*链表的插入(在指定位置之后插入)*/
void behind_insert(Node *head, int position, int value)
{
Node *p = head;
Node *q = NULL;
int i = 0;
while(p && i++ < position)
{
p = p->next;
}
q = (Node *)malloc(sizeof(Node));
q->data = value;
q->next = p->next;
p->next = q;
}
阅读(1029) | 评论(0) | 转发(0) |