这是本人对队列链式结构综合运用写的一段代码,但是输出入队的data值是乱码,不是入队的值,请问为什么会这样的呢?

这是本人对队列链式结构综合运用写的一段代码,但是输出入队的data值是乱码,不是入队的值,请问为什么会这样的呢?
#include
#include
typedef struct linknode
{
int data;
struct linknode *next;
}linknode;
typedef struct
{
linknode *front,rear;
}linkqueue;
void initqueue(linkqueue &L)
{
L.front=L.rear=(linknode
)malloc(sizeof(linknode));
L.front->next=NULL;
}
void enqueue(linkqueue L,int x)
{
linknode p=(linknode)malloc(sizeof(linknode));
p->data=x;
p->next=NULL;
L.rear->next=p;
L.rear=p;
}
int dequeue(linkqueue L,int &x)
{
if(L.front==L.rear)
return -1;
linknode *p=L.front->next;
x=p->data;
L.front->next=p->next;
if(L.rear==p)
L.rear=L.front;
else
free(p);
return 1;
}
int isempty(linkqueue L)
{
if(L.front==L.rear)
return 1;
else
return -1;
}
int main()
{
int x;
linkqueue s;
initqueue(s);
enqueue(s,3);
printf("%d\n",s.rear->data);
if(dequeue(s,x))
printf("%d\n",dequeue(s,x));
if(isempty(s))
printf("%d\n",isempty(s));
}

修改处见注释,供参考:

#include <stdio.h>
#include <stdlib.h>
typedef struct linknode
{
    int data;
    struct linknode *next;
}linknode;
typedef struct
{
    linknode *front,*rear;
}linkqueue;
void initqueue(linkqueue &L)
{
    L.front=L.rear=(linknode*)malloc(sizeof(linknode));
    L.front->next=NULL;
}
void enqueue(linkqueue &L,int x) //修改
{
    linknode* p=(linknode*)malloc(sizeof(linknode));
    p->data = x;
    p->next = NULL;
    if (L.front->next == NULL) //修改
        L.front->next = p;     //修改
    L.rear->next = p;
    L.rear = p;
}
int dequeue(linkqueue &L,int &x) //修改
{
    if(L.front == L.rear)
       return -1;
    linknode *p = L.front->next;
    x = p->data;
    L.front->next = p->next;
    if(L.rear == p)
       L.rear = L.front;
    //else         //修改
    free(p);
    return 1;
}
int isempty(linkqueue L)
{
    if(L.front == L.rear)
       return 1;
    else
       return -1;
}
int main()
{
    int x;
    linkqueue s;
    initqueue(s);
    enqueue(s,3);
    printf("%d\n",s.rear->data);
    if(dequeue(s,x))
       printf("%d\n",dequeue(s,x));

    if(isempty(s))
       printf("%d\n",isempty(s));

    return 0;
}

试试将linkqueue结构体改成如下:

typedef struct
{
linknode *front;
linknode *rear;
}linkqueue;

printf("%d\n",dequeue(s,x));
你这输出的是dequeue函数的返回值1啊,链表的值是x啊