调用equal函数后,涉及到equal函数的语句不运行

问题:建表输出正常,但是调用equal函数后不输出不运行,是哪里写的不对吗?
题目:判断循环双链表L是否对称

#include
#include
typedef int ElemType;
typedef struct DLnode
{
    int data;
    struct DLnode *next;
    struct DLnode *prior;
}DLinkNode;
void InitList(DLinkNode *&L)
{
    L=(DLinkNode *)malloc(sizeof(DLinkNode));
    L->prior=L->next=NULL;
}
void CreatList(DLinkNode *&L,int a[],int n)
{
    DLinkNode *p,*r;
    L=(DLinkNode *)malloc(sizeof(DLinkNode));
    r=L;
    for(int i=0;imalloc(sizeof(DLinkNode));
        p->data=a[i];
        r->next=p;
        p->prior=r;
        r=p;
    }
    r->next=NULL;
}
void DispList(DLinkNode *&L)
{
    DLinkNode *p=L->next;
    while(p!=NULL)
    {
        printf("%d ",p->data);
        p=p->next;
    }
}
bool equal(DLinkNode *L)
{
    bool same=true;
    DLinkNode *p=L->next,*q=L->prior;
    while(same)
    {
        if(q->data!=p->data)
          same=false;
        else
        {
            if(p==q||p->next==q)   break;
            p=p->next;
            q=q->prior;
        }
    }
    return same;
}
int main()
{
    DLinkNode *L;
    int a[7];
    InitList(L);
    printf("请输入:");
    for(int i=0;i<7;i++)
    {
        scanf("%d",&a[i]);
    }
    CreatList(L,a,7);
    printf("请输出:");
    DispList(L);
    equal(L);
    printf("链表是%s的",(equal(L))?"对称":"不对称");
}

img

改动处见注释,供参考:

//题目:判断循环双链表L是否对称
#include<stdio.h>
#include<malloc.h>
typedef int ElemType;
typedef struct DLnode
{
    int data;
    struct DLnode *next;
    struct DLnode *prior;
}DLinkNode;
void InitList(DLinkNode *&L)
{
    L=(DLinkNode *)malloc(sizeof(DLinkNode));
    L->prior=L->next=L;  //L->prior=L->next=NULL; 修改
}
void CreatList(DLinkNode *&L,int a[],int n)
{
    DLinkNode *p,*r;
    //L=(DLinkNode *)malloc(sizeof(DLinkNode));  修改 这句多余
    r=L;
    for(int i=0;i<n;i++)
    {
        p=(DLinkNode *)malloc(sizeof(DLinkNode));
        p->data=a[i];
        p->next=L;     //修改
        r->next=p;
        p->prior=r;
        L->prior=p;    //修改
        r=p;
    }
       //r->next=NULL;  修改
}
void DispList(DLinkNode *&L)
{
    DLinkNode *p=L->next;
    while(p != L)   //while(p!=NULL)修改
    {
        printf("%d ",p->data);
        p=p->next;
    }
    printf("\n");    //修改
}
bool equal(DLinkNode *L)
{
    bool same=true;
    DLinkNode *p=L->next,*q=L->prior;
    while (p != L && q != L)
    {
        if (p->data == q->data)
        {
            p=p->next;
            q=q->prior;
        }
        else
            break;
    }
    same=(p==L&&q==L) ? true : false;
    //while(same)      //修改
    //{
    //    if(q->data!=p->data)
    //      same=false;
    //    else
    //    {
    //        if(p==q||p->next==q)   break;
    //        p=p->next;
    //        q=q->prior;
    //    }
    //}
    return same;
}
int main()
{
    DLinkNode *L;
    int a[7];
    InitList(L);
    printf("请输入:");
    for(int i=0;i<7;i++)
    {
        scanf("%d",&a[i]);
    }
    CreatList(L,a,7);
    printf("请输出:");
    DispList(L);
    //equal(L);  //修改
    printf("链表是%s的",(equal(L))?"对称":"不对称");

    return 0;
}