typedef int ElemType;
typedef struct Node{
ElemType data;
struct Node *next;
}Node;
typedef struct Node *linkList;
bool GetElem(linkList L, int i, ElemType *e)
{
int j;
linkList p;
p = L->next;
j = 1;
while(p && j < i)
{
p = p->next;
++j;
}
if(!p ||j >i)
return false;
*e = p->data;
return true;
}
bool ListInsert(linkList *L, int i, ElemType e)
{
int j;
linkList p, s;
j = 1;
p = *L;
while(p && j < i)
{
p = p->next;
++j;
}
if(!p|| j> i)
return false;
s =(linkList) malloc(sizeof(Node));
s->data = e;
s->next = p->next;
p->next = s;
return true;
}
bool ListDelete(linkList *L, int i, ElemType *e)
{
int j;
linkList p, q;
j = 1;
p = *L;
while(p->next && j <i)
{
p = p->next;
++j;
}
if(!(p->next) !! j > i)
return false;
q = p->next;
p->next = q->next;
*e = q->data;
free(q);
return true;
}
void CreateListHead(linkList *L, int n)
{
linkList p;
int i;
srand(time(0));
*L = (linkList)malloc(sizeof(Node));
(*L)->next = NULL;
for(i = 0; i < n; i++)
{
p = (linkList)malloc(sizeof(Node));
p->data = rand()%100+1;
p->next = (*L) ->next;
(*L)->next = p;
}
}
void CreateListTail(linkList *L, int n)
{
linkList p, r;
int i;
srand(time(NULL));
*L = (linkList) malloc(sizeof(Node));
r = *L;
for(i = 0; i < n; i++)
{
p =(linkList)malloc(sizeof(Node));
p->data = rand()%100+1;
r->next = p;
r = p;
}
r->next = NULL;
}
bool ClearList(linkList *L)
{
linkList q, p;
p = (*L)->next;
while(p)
{
q = p->next;
free(p);
p = q;
}
}
typedef struct Node{
ElemType data;
struct Node *next;
}Node;
typedef struct Node *linkList;
bool GetElem(linkList L, int i, ElemType *e)
{
int j;
linkList p;
p = L->next;
j = 1;
while(p && j < i)
{
p = p->next;
++j;
}
if(!p ||j >i)
return false;
*e = p->data;
return true;
}
bool ListInsert(linkList *L, int i, ElemType e)
{
int j;
linkList p, s;
j = 1;
p = *L;
while(p && j < i)
{
p = p->next;
++j;
}
if(!p|| j> i)
return false;
s =(linkList) malloc(sizeof(Node));
s->data = e;
s->next = p->next;
p->next = s;
return true;
}
bool ListDelete(linkList *L, int i, ElemType *e)
{
int j;
linkList p, q;
j = 1;
p = *L;
while(p->next && j <i)
{
p = p->next;
++j;
}
if(!(p->next) !! j > i)
return false;
q = p->next;
p->next = q->next;
*e = q->data;
free(q);
return true;
}
void CreateListHead(linkList *L, int n)
{
linkList p;
int i;
srand(time(0));
*L = (linkList)malloc(sizeof(Node));
(*L)->next = NULL;
for(i = 0; i < n; i++)
{
p = (linkList)malloc(sizeof(Node));
p->data = rand()%100+1;
p->next = (*L) ->next;
(*L)->next = p;
}
}
void CreateListTail(linkList *L, int n)
{
linkList p, r;
int i;
srand(time(NULL));
*L = (linkList) malloc(sizeof(Node));
r = *L;
for(i = 0; i < n; i++)
{
p =(linkList)malloc(sizeof(Node));
p->data = rand()%100+1;
r->next = p;
r = p;
}
r->next = NULL;
}
bool ClearList(linkList *L)
{
linkList q, p;
p = (*L)->next;
while(p)
{
q = p->next;
free(p);
p = q;
}
}