回 帖 发 新 帖 刷新版面

主题:队列的链式问题

#include<stdio.h>
#include<stdlib.h>
typedef struct NODE
{
    int data;
    struct NODE *next;
}node;
void enqueue(node *front,node *rear,int x)
{
    node *temp;
    temp=(node *)malloc(sizeof(node));
    if(temp==NULL)printf("溢出\n");
    else
    {
        temp->data=x;
        temp->next=NULL;
        if(rear==NULL)
        {
            front=temp;
            rear=temp;
        }
        else
        {
            rear->next=temp;
            rear=temp;
        }
    }
}
void main()
{
    node *front,*rear;
    front=NULL;
    rear=NULL;
    enqueue(front,rear,1);
    enqueue(front,rear,2);
    printf("%d",front->data);
}


查不出哪错了,帮帮忙,谢谢

回复列表 (共5个回复)

沙发

呵呵 没看明白你要实现的功能是什么!!

板凳

链式的队列的建立,因为建立时已经出错了,剩余部分就省略了。我认为是置空错了,但查不出错哪

3 楼

void enqueue(node **front,node **rear,int x)
{
    node *temp;
    temp=(node *)malloc(sizeof(node));
    if(temp==NULL)printf("溢出\n");
    else
    {
        temp->data=x;
        temp->next=NULL;
        if(*rear==NULL)
        {
            *front=temp;
            *rear=temp;
        }
        else
        {
            (*rear)->next=temp;
            (*rear)=temp;
        }
    }
}


void main()
{
    node *front,*rear;
    front=NULL;
    rear=NULL;
    enqueue(&front,&rear,1);
    enqueue(&front,&rear,2);
    printf("%d",front->data);
}

4 楼

你先把这个程序主要是用来做什么的告诉我们
我门才能容易的看不那出错了

5 楼

说得对啊!!~~~~~~~~~~~~~~

我来回复

您尚未登录,请登录后再回复。点此登录或注册