📄 3_2.txt
字号:
#include<stdio.h>
typedef struct node{ /*结点类型*/
int data;
struct node *next;
}Llist;
insert(Llist **h,int x,int kind) /*kind=1:插在表头,kind=2:插在表尾*/
/*(*h)为指向表尾的指针*/
{
Llist *s,*q;
s=(Llist *)malloc(sizeof(Llist));
s->data=x;
if((*h)->next==*h) /*循环链表为空*/
{
s->next=*h;
(*h)->next=s;
*h=s;
}
else
if(kind==1)
{ q=(*h)->next;
s->next=q->next;
q->next=s;
}
else{
s->next=(*h)->next;
(*h)->next=s;
*h=s;
}
}
main()
{
Llist *h,*p;
h=(Llist *)malloc(sizeof(Llist));
h->next=h;
insert(&h,1,2);
insert(&h,10,2);
insert(&h,-1,1);
p=h->next->next;
while(p!=h->next){
printf("%d ",p->data);
p=p->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -