我在编写循环链表程序的时候出现Process returned -1073741819 (0xC0000005)的情况,
请问是指针的使用出现问题了吗,还是其他的问题呢?
另外 ListNode* a[N]; //can I create an array using N?
这个可以以形参N作为输入创建数组吗?
以下是我的代码,谢谢!
#include <stdio.h>
#include <stdlib.h>
//define a node
typedef struct ListNode
{
int val;
struct ListNode* next;
}ListNode;
//construct a linked list Cycle
void makecycle(int N)
{
int i;
ListNode* a[N]; //can I create an array using N?
a[1]->next = a[2];
a[1]->val = 1;
for(i = 2; i < N; i++)
{
a[i]->next = a[i+1];
a[i]->val = i;
}
a[N]->next = a[1];
a[N]->val = N;
}
//input needed variables
int main()
{
int N, A, B, K;
scanf("%d %d %d %d", &N, &A, &B, &K);
makecycle(N);
}