| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2895 人关注过本帖
标题:关于队列链式的问题
只看楼主 加入收藏
a285966121
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-2-29
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
关于队列链式的问题
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 100
#define ERROR -1
#define true 0
typedef char ElementType;

typedef struct LNode {
    ElementType a;
    struct LNode *next;
}*List;
typedef struct Link
{
    List front,rear;
}*QNde;
MakeEmpty(QNde *s)
{
    (*s)->front=(*s)->rear=(List)malloc(sizeof(struct LNode));
    (*s)->front=(*s)->rear;
    (*s)->front->next=NULL;
}

void enter(QNde *s,ElementType x)
{
    List t;
    t=(List)malloc(sizeof(struct LNode));
    t->a=x;
    t->next=NULL;
    if((*s)->front->next==NULL)
    {
        (*s)->front->next=t;
        (*s)->rear->next=t;
    }
    else
    {
        t=(*s)->rear->next->next;
        (*s)->rear->next=t;
    }
}
void delete(QNde *s)
{
    List q;
    if((*s)->front->next==NULL)
      printf("队空");
    else
    {
        if((*s)->front->next==(*s)->rear->next)
        {
            q=(*s)->front->next;
            (*s)->front->next=NULL;
            (*s)->rear->next=NULL;
        }
        else
        {
            q=(*s)->front->next;
            (*s)->front->next=q->next;
        }
        free(q);
    }
}
void display(QNde *s)
{
    List q;
    q=(*s)->front->next;
    printf("队的显示:\n");
    if((*s)->front->next==NULL)
      printf("空队");
    else
    {
        if((*s)->front->next==(*s)->rear->next)
        {
            printf("%c",q->a);
        }
        else
        {
            while(q->next!=NULL)
            {
                printf("%c",q->a);
                q=q->next;
            }
            printf("%c",q->a);
        }
    }
    printf("\n");
}
main()
{
    QNde *qu;
    printf("初始化队列 qu\n");
    MakeEmpty(qu);
    printf("依次入队 a,b,c,d 元素\n");
    enter(qu,'a');
    enter(qu,'b');
    enter(qu,'c');
    enter(qu,'d');
    display(qu);
    printf("出队一次\n");
    delete(qu);
    display(qu);
    printf("出队一次\n");
    delete(qu);
    display(qu);
}
问下哪错了,运行不出来,谢谢....
搜索更多相关主题的帖子: include 
2016-03-24 21:42
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <malloc.h>
#define MAXSIZE 100
#define ERROR -1
#define true 0
typedef char ElementType;

typedef struct LNode {
    ElementType a;
    struct LNode *next;
}List;
typedef struct Link
{
    List *front,*rear;
}QNde;
void MakeEmpty(QNde *s)
{
    s=(QNde*)malloc(sizeof(QNde));
    s->front=s->rear=NULL;
}

void enter(QNde *s,ElementType x)
{
    List *t;
    t=(List*)malloc(sizeof(List));
    t->a=x;
    t->next=NULL;
    if(s->front==NULL)
    {
        s->front=s->rear=t;
    }
    else
    {
        s->rear->next=t;
        s->rear=t;
    }
}
void delete1(QNde *s)
{
    List *q;
    if(s->front==NULL)
      printf("队空");
    else
    {
        if(s->front==s->rear)
        {
            q=s->front;
            s->front=s->rear=NULL;
        }
        else
        {
            q=s->front;
            s->front=s->front->next;
        }
        free(q);
    }
}
void display(QNde *s)
{
    List *q;
    q=s->front;
    printf("队的显示:\n");
    if(s->front->next==NULL)
      printf("空队");
    else
    {
        if(s->front->next==s->rear->next)
        {
            printf("%c",q->a);
        }
        else
        {
            while(q->next!=NULL)
            {
                printf("%c",q->a);
                q=q->next;
            }
            printf("%c",q->a);
        }
    }
    printf("\n");
}
main()
{
    QNde *qu;
    printf("初始化队列 qu\n");
//    MakeEmpty(qu);
    qu=(QNde*)malloc(sizeof(QNde));
    qu->front=qu->rear=NULL;
    printf("依次入队 a,b,c,d 元素\n");
    enter(qu,'a');
    enter(qu,'b');
    enter(qu,'c');
    enter(qu,'d');
    display(qu);
    printf("出队一次\n");
    delete1(qu);
    display(qu);
    printf("出队一次\n");
    delete1(qu);
    display(qu);
}

剑栈风樯各苦辛,别时冰雪到时春
2016-03-27 09:36
快速回复:关于队列链式的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017595 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved