You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#pragma once
|
|
|
|
|
#include"List.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
int InitList(LinkList *L)
|
|
|
|
|
{
|
|
|
|
|
*L = (LinkList)malloc(sizeof(Node_List)); /* <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>,<2C><>ʹLָ<4C><D6B8><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD> */
|
|
|
|
|
if (!(*L)) /* <20>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7> */
|
|
|
|
|
return 0;
|
|
|
|
|
(*L)->next = NULL; /* ָ<><D6B8><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA> */
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
int ListInsert(LinkList *L, int i, int e)
|
|
|
|
|
{
|
|
|
|
|
int j;
|
|
|
|
|
LinkList p, s;
|
|
|
|
|
p = *L;
|
|
|
|
|
j = 1;
|
|
|
|
|
while (p && j < i) /* Ѱ<>ҵ<EFBFBD>i<EFBFBD><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
{
|
|
|
|
|
p = p->next;
|
|
|
|
|
++j;
|
|
|
|
|
}
|
|
|
|
|
if (!p || j > i)
|
|
|
|
|
return 0; /* <20><>i<EFBFBD><69>Ԫ<EFBFBD>ز<EFBFBD><D8B2><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
s = (LinkList)malloc(sizeof(Node_List)); /* <20><><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD>(C<><43><EFBFBD>Ա<EFBFBD><EFBFBD><D7BC><EFBFBD><EFBFBD>) */
|
|
|
|
|
s->data = e;
|
|
|
|
|
s->next = p->next; /* <20><>p<EFBFBD>ĺ<EFBFBD><C4BA>̽<EFBFBD><CCBD>㸳ֵ<E3B8B3><D6B5>s<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD> */
|
|
|
|
|
p->next = s; /* <20><>s<EFBFBD><73>ֵ<EFBFBD><D6B5>p<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD> */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|