1,先建立结构体
struct node{
int num;
struct node *next;
};
2,建立创建循环链表的函数
struct node* creat(){
struct *head;*now,*pre; //分别为头节点,当前节点,前驱节点
for(int i = 0;i<=n;i++){
now = (struct node*)malloc(sizeof(node));
if(i==1){
head=now;//头节点指向第一个节点
pre=now;//上一个节点也指向它
}
now->num=i; //以下操作吧新的节点加入到循环链表
now->next=head;
pre->next=now;
pre=now;
}
return head;
}
后面用到就可以直接用了