?? linlist.h
字號:
typedef struct Node
{
LinDataType data;
struct Node *next;
}
SLNode;
void LinListInitiate(SLNode **head) //初始化
{
if((*head=(SLNode *)malloc(sizeof(SLNode)))==NULL)exit(1);
(*head)->next=NULL;
}
int LinListLength(SLNode *head)
{
SLNode *p =head;
int size=0;
while(p->next!=NULL)
{
p=p->next;
size++;
}
return size;
}
int LinListInsert(SLNode *head,int i,LinDataType x)
{
SLNode *p,*q;
int j;
p=head;
j=-1;
while(p->next!=NULL&&j<i-1)
{
p=p->next;
j++;
}
if(j!=i-1)
{
printf("插入位置參數(shù)錯(cuò)!\n");
return 0;
}
if((q=(SLNode *)malloc(sizeof(SLNode)))==NULL) exit(0);
q->data=x;
q->next=p->next;
p->next=q;
return 1;
}
int LinListDelete(SLNode *head,int i,LinDataType *x)
{
SLNode *p,*s;
int j;
p=head;
j=-1;
while(p->next!=NULL&&p->next->next!=NULL&&j<i-1)
{
p=p->next;
j++;
}
if(j!=i-1)
{
printf("刪除位置錯(cuò)!\n");
return 0;
}
s=p->next;
*x=s->data;
p->next=p->next->next;
free(s);
return 1;
}
int LinListGet(SLNode *head,int i,LinDataType *x)
{
SLNode *p;
int j ;
p=head;
j=-1;
while(p->next!=NULL&&j<i)
{
p=p->next;
j++;
}
if(j!=i)
{
printf("取元素位置參數(shù)錯(cuò)!\n");
return 0;
}
*x=p->data;
return 1;
}
void LinDestroy(SLNode *head)
{
SLNode *p,*p1;
p=head;
while(p!=NULL)
{
p1=p;
p=p->next;
free(p1);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -