📄 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("插入位置参数错!\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("删除位置错!\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("取元素位置参数错!\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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -