【循环链表】求助,提交说我没有定义链表!
查看原帖
【循环链表】求助,提交说我没有定义链表!
835960
dongtian楼主2023/10/22 13:12
#include<stdio.h>
#include<stdlib.h>

struct seqlist{
	int data;
	struct seqlist *next;
};

int main() {
	seqlist *list, *head, *temp;
	int n, m, i;
	scanf("%d%d",&n,&m);
	head = list = (seqlist *)malloc(sizeof(seqlist));
	for(i = 1;i <= n;i ++) {
		list->data = i;
		if(i < n) {
			list->next = (seqlist *)malloc(sizeof(seqlist));
		list = list->next;
		}
		
	}
	list->next = head;
	while(head != head->next) {
		for(i = 1;i < m - 1;i ++) {
			head = head->next;
		}
		temp = head->next;
		printf("%d ",temp->data);
		head->next = head->next->next;
		temp = NULL;
		free(temp);
		head = head->next;
	}
	printf("%d",head->data);
	return 0;
}
2023/10/22 13:12
加载中...