| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 731 人关注过本帖
标题:程序中有点小问题,求解????
只看楼主 加入收藏
Nield
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-23
结帖率:0
收藏
 问题点数:0 回复次数:2 
程序中有点小问题,求解????
#include<stdio.h>
#include<stdlib.h>
#define NULL 0

typedef struct node
{
    char c;
    struct node *next;
}qnode;

typedef struct
{
    qnode *head;
    qnode *rear;
}queue;
//构建队列
void getqueue(queue *q)
{
    char ch;
    qnode *l,*p;
    q=(queue *)malloc(sizeof(queue));
    q->head=NULL;
    q->rear=NULL;
    printf("请输入队列元素:\n");
    scanf("%c",&ch);
    getchar();

    while(ch!='!')
    {
        p=(qnode *)malloc(sizeof(qnode));
        p->next=NULL;
        p->c=ch;
        if(q->head==NULL)
        {
            q->head=p;
            l=p;
        }
        l->next=p;
        l=p;
        q->rear=p;
        scanf("%c",&ch);
        getchar();
    }
    l=q->head;
    while(l!=NULL)
    {
        printf("%c<--",l->c);
        l=l->next;
    }
    printf("\n队头元素是%c; 队尾元素是%c\n",q->head->c,q->rear->c);
}

void in_out(queue *q)
{
    char ch;
    int x;
    qnode *p,*l;
    printf("输入‘1’进队;输入‘2’出队!;其他退出!!!\n");
    scanf("%d",&x);
    while(x==1)//进队
    {
        printf("请输入进队元素:");
        scanf("%c",&ch);
        getchar();
        p=(qnode *)malloc(sizeof(qnode));
        p->c=ch;
        p->next=NULL;
        l=q->rear;
        l->next=p;
        q->rear=p;
        printf("输入‘1’进队;输入‘2’出队!;其他退出!!!\n");
        scanf("%d",&x);
    }
    while(x==2)//出队
    {
        q->head=q->head->next;
        printf("输入‘1’进队;输入‘2’出队!;其他退出!!!\n");
        scanf("%d",&x);
    }
    while(x!=1||x!=2)
    {
        exit(0);
    }
    l=q->head;
    while(l!=NULL)
    {
        printf("%c<--",l->c);
        l=l->next;
    }
    printf("\n队头元素是%c; 队尾元素是%c\n",q->head->c,q->rear->c);
}

void main()
{
    int i;
    queue *q;
    getqueue(&q);
    in_out(&q,i);
}
搜索更多相关主题的帖子: next include 
2013-05-17 15:32
Nield
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-4-23
收藏
得分:0 
带颜色的部分有点小问题,求解啊
?????????
2013-05-17 15:34
邓士林
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:淮河河畔
等 级:贵宾
威 望:61
帖 子:2392
专家分:13384
注 册:2013-3-3
收藏
得分:0 
语法没错误啊

Maybe
2013-05-20 10:08
快速回复:程序中有点小问题,求解????
数据加载中...
 
   



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

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