文章
34
粉丝
316
获赞
10
访问
22.3k
//就按照题目说的用链表实现把
#include<stdio.h>
#include<malloc.h>
struct LNode
{
int data;
struct LNode* next;
};
int main()
{
int n;
scanf("%d", &n);
//先创建循环链表(不带头结点的种)
struct LNode* head = (struct LNode*)malloc(sizeof(struct LNode));
head->next = NULL;
head->data = 1;
//采用头插法
for (int i = n; i >= 2; i--) {
struct LNode* newNode = (struct LNode*)malloc(sizeof(struct LNode));
newNode->data = i;
newNode->next = head->next;
head->next = newNode;
if (i == n) newNode->next = head;
...
登录后发布评论
暂无评论,来抢沙发