出圈游戏的程序,编写了一下,但是有有关问题。大家伙帮忙给看看,万分感激!

出圈游戏的程序,编写了一下,但是有问题。大家伙帮忙给看看,万分感激!!!!!
main()
{
struct A * p = (struct A *)malloc(sizeof(struct A)*10);
for(int j = 0 ; j<9;j++)
{
p[j].num = j;
p[j].next = &p[j+1];
if(j == 0)
{
p[j].pre = &p[9];
}
}
p[9].num = 9;
p[9].pre = &p[9-1];
p[9].next = &p[0];
int i = 1;
while(i<9)
{
int k =1;
struct A * q = p;
while(k<3)
{
q = q ->next;
k++;
}
q->pre->next = q->next;
q->next->pre = q->pre;
p = q ->next;
free(q);
q = NULL;
i++;
}
int f = p->num;
std::cout<<f<<std::endl;
}

就在上面标注的地方,运行时出错。不知道问什么,恳求高手支招!!!

------解决方案--------------------
什么是出圈游戏??