| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 515 人关注过本帖
标题:大家都来看看,能帮的酒帮帮我吧!
只看楼主 加入收藏
a597910538
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2011-5-21
结帖率:100%
收藏
已结贴  问题点数:5 回复次数:8 
大家都来看看,能帮的酒帮帮我吧!
    我要的程序是对队列的使用,即将若干个元素存入队列(链式存储结构的队列)中,然后再将队列中元素输出!元素入队和出队都是用函数来完成!
    本来是不会这样提出来问大家的,但是前几次我把我写的程序拿出来给大家改,可是就是没有一个人帮我把错误的地方改好!也许我写程序的思路大家还不清楚吧,所以现在希望帮我的朋友用你们的思路帮我写出这个程序!谢谢!
搜索更多相关主题的帖子: 我的朋友 
2011-06-12 16:04
bccn_2012
Rank: 6Rank: 6
等 级:侠之大者
帖 子:158
专家分:447
注 册:2011-5-14
收藏
得分:0 
你写的程序可否在贴上来一次??
2011-06-12 16:22
laoyang103
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:内蒙古包头
等 级:贵宾
威 望:19
帖 子:3082
专家分:11056
注 册:2010-5-22
收藏
得分:5 
程序代码:
#include<stdio.h>
#include <malloc.h>
#include <string.h>
struct Node
{
    int num;
    Node *next;
};

class Queue
{
public:
    Queue();
    ~Queue();
    void push_back(Node node);
    Node get_front();
    void pop_front();
    void fun(Node *p);
private:
    Node *front;
    Node *tail;
};

Queue::Queue()
{
    front = (Node *)malloc(sizeof(Node));
    memset(front,0,sizeof(Node));
    tail = (Node *)malloc(sizeof(Node));
    memset(tail,0,sizeof(Node));
    front->next = tail;
}

void Queue::fun(Node *p)//递归释放链表
{
    if(p->next != NULL)
        fun(p->next);
    free(p);
}

Queue::~Queue()
{
}
void Queue::push_back(Node node)
{
    *tail = node;
    tail->next = (Node *)malloc(sizeof(Node));
    tail = tail->next;
    memset(tail,0,sizeof(Node));   
}

Node Queue::get_front()
{
    return *(front->next);
}

void Queue::pop_front()
{
    Node *p = front->next;
    front->next = front->next->next;
    free(p);
}


void main()
{
    Queue q;
    Node a[5] = {{1,0},{2,0},{3,0},{4,0},{5,0}};
    int i,j,k;
    for(i = 0;i<5;i++)
        q.push_back(a[i]);
    for(i = 0;i<5;i++)
    {
        printf("%d ",q.get_front());
        q.pop_front();
    }
} 

给你 拿去吧

[ 本帖最后由 laoyang103 于 2011-6-12 17:08 编辑 ]

                                         
===========深入<----------------->浅出============
2011-06-12 16:58
a597910538
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2011-5-21
收藏
得分:0 
回复 3楼 laoyang103
谢谢!楼上的!
2011-06-12 19:59
a597910538
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2011-5-21
收藏
得分:0 
回复 2楼 bccn_2012
#include<stdio.h>
#include<malloc.h>
#define maxsize 100
typedef struct node1
{
    char data;
    struct node1 *next;
}LINKQLIST;

typedef struct
{
    LINKQLIST *front,*rear;
}production;//生产
void initlinkqueuep(production *q)//初始化
{
    q->front=(LINKQLIST *)malloc(sizeof(LINKQLIST));
    (q->front)->next=NULL;
    q->rear=q->front;
}
char getlinkfrnetp(production *q)//数据读取
{
    char v;
    if(q->front==q->rear)
        printf("没有生产计划\n");
    else
        v=(q->front)->next->data;
    return v;
   
}

void enlinkqueuep(production *q,char x)//插入数据
{
        (q->rear)->next =(LINKQLIST *)malloc(sizeof(LINKQLIST));
        q->rear=(q->rear)->next;
        q->rear->data=x;
        (q->rear)->next=NULL;
}
void main()//这个主函数的功能是  初始化队列===》将一组数据存入队列中===》输出队列中的数据
{
    production q;
    int i,j=0;
    char ch[maxsize];
    initlinkqueuep(&q);
    //enlinkqueuep(&q,'A');
    for(i=0;i<maxsize;i++)
    {
        scanf("%c",&ch[i]);
        enlinkqueuep(&q,ch[i]);
        if(ch[i]='\n')
            break;
    }
    //printf("%c",getlinkfrnetp(&q));
   for(i=0;i<maxsize;i++)
   {
        printf("%c",getlinkfrnetp(&q));
   }

}
2011-06-12 20:00
a597910538
Rank: 1
等 级:新手上路
帖 子:20
专家分:3
注 册:2011-5-21
收藏
得分:0 
链队(vc6.0成功编译的)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define maxsize 100
typedef struct node1
{
    char data;
    struct node1 *next;
}LINKQLIST;

typedef struct
{
    LINKQLIST *front;
    LINKQLIST *rear;
}production;//生产
void initlinkqueuep(production *q)//初始化
{
    q->front=(LINKQLIST *)malloc(sizeof(LINKQLIST));
    (q->front)->next=NULL;
    q->rear=q->front;
}
char getlinkfrnetp(production *q)//数据读取
{
    char v;
    if(q->front==q->rear)//判断队列是否为空
        printf("没有生产计划\n");
    else
    {
        v=(q->front)->next->data;//将队首元素赋值给V
        q->front=(q->front)->next;
    }
    return v;
   
}

void enlinkqueuep(production *q,char x)//插入数据
{
        (q->rear)->next =(LINKQLIST *)malloc(sizeof(LINKQLIST));//给元素创建存储空间
        q->rear=(q->rear)->next;        //将为节点传给下一个
        q->rear->data=x;            //将值存入节点中            
        (q->rear)->next=NULL;
        
}

void main()//这个主函数的功能是  初始化队列===》将一组数据存入队列中===》输出队列中的数据
{
    production q;
    int i,j,k=0;
    char ch;
    initlinkqueuep(&q);//初始化
    while((ch=getchar())!='\n')
    {
        enlinkqueuep(&q,ch);
        k++;
    }
   for(j=0;j<k;j++)
   {
        printf("%c",getlinkfrnetp(&q));//输出队首元素
   }
}
2011-06-13 15:46
chenhongzhi
Rank: 1
等 级:新手上路
帖 子:13
专家分:8
注 册:2011-6-13
收藏
得分:0 
这么难,我不会
2011-06-13 16:24
chenhongzhi
Rank: 1
等 级:新手上路
帖 子:13
专家分:8
注 册:2011-6-13
收藏
得分:0 
我也是新手
2011-06-13 16:24
bccn_2012
Rank: 6Rank: 6
等 级:侠之大者
帖 子:158
专家分:447
注 册:2011-5-14
收藏
得分:0 
回复 5楼 a597910538
一个结构体就可以解决,为什么要用两个?
2011-06-13 16:48
快速回复:大家都来看看,能帮的酒帮帮我吧!
数据加载中...
 
   



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

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