| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3852 人关注过本帖
标题:求链队列的一些基本操作
只看楼主 加入收藏
默声人
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-25
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
求链队列的一些基本操作
求链队列的个数、判空、出入队的基本代码操作?
          急急急!!!
2012-10-29 21:33
pauljames
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:千里冰封
威 望:9
帖 子:1555
专家分:10000
注 册:2011-5-8
收藏
得分:7 
数据结构书上有,去找找

经常不在线不能及时回复短消息,如有c/单片机/运动控制/数据采集等方面的项目难题可加qq1921826084。
2012-11-03 07:18
梁朝斌
Rank: 4
等 级:业余侠客
帖 子:192
专家分:288
注 册:2012-10-21
收藏
得分:7 
#include<stdio.h>
#include<math.h>
#define maxsize 50
int main(void)
{
    double x[maxsize],y[maxsize],a,b,aa,p,sum;
    int i,k,n;

    printf("please input a= and b=\n");
    scanf("%d %d",&a,&b);

    printf("please input n=\n");
    scanf("%d",&n);

    printf("please input aa=\n");
    scanf("%lf",&aa);

    printf("please input x[i]= \n");
    for(i=0;i<=n;i++)
        scanf("%lf",&x[i]);

    printf("please input y[k]= \n");
    for(k=0;k<=n;k++)
    {
        scanf("%lf\n",&x[k]);
        scanf("%lf\n",&y[k]);
    }
   

   
    if(x[0]>=a&&x[n]<=b)
    {
        printf("输入错误,请重新输入!\n");
        return 0;
    }
    sum=0;
    for(k=0;k<=n;k++)
    {
        p=1;
        for(i=0;i<=n;i++)
        {
            if(i!=k)
            {
                p=p*(aa-x[i])/(x[k]-x[i]);                     
                sum+=p*y[k];
            }
        }
    }
    printf("sum=%d",sum);
    return 0;
}

菜鸟也疯狂
2012-11-03 13:40
梁朝斌
Rank: 4
等 级:业余侠客
帖 子:192
专家分:288
注 册:2012-10-21
收藏
得分:0 
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define OK 1
int yes=0;
typedef struct node
{
    char data;
    struct node *next;
}node,*queueptr;
typedef struct
{
    queueptr front;
    queueptr rear;
}linkqueue;
void initqueue(linkqueue *q)
{
    q->front=q->rear=(queueptr)malloc(sizeof(node));
    if(!(q->front))
        exit(1);
    q->front->next=0;
}
void enqueue(linkqueue *q,char e)
{
    queueptr p;
    p=(queueptr)malloc(sizeof(node));
    if(!p)exit(1);
    p->data=e;
    p->next=0;
    q->rear->next=p;
    q->rear=p;
}
void creatqueue(linkqueue *q)
{
    int i,length;
    char ch;
    queueptr p;
    printf("请输入队列长度:\n");
    scanf("%d",&length);
    printf("请输入队列的元素:\n");
    for(i=0;i<length;i++)
    {
        p=(queueptr)malloc(sizeof(node));
        if(!p)exit(1);
        scanf("%c",&ch);
        if((ch=getchar())!='\n')
        {
            p->data=ch;
            p->next=0;
            q->rear->next=p;
            q->rear=p;
        }
        else
        i--;
    }
    yes=1;
}
void destroyqueue(linkqueue *q)
{
    if(q)
    {
        printf("栈队列已经是空队列!\n");
        exit(1);
    }
    while(q->front)
    {
        q->rear=q->front->next;
        free((q->front));
        q->front=q->rear;
        if(!q->rear)
            free(q->rear);
    }
    free(q->front);
}
   
    void disqueue(linkqueue *q)
    {
        node *r=q->front->next;
        printf("此时的栈队列输出:\n");
        while(r)
        {
            printf("%c\t",r->data);
            r=r->next;
        }
        printf("\n");
    }
    void lenqueue(linkqueue *q)
    {
        node *r=q->front->next;
        int s=0;
        printf("此时的栈队列长度为:\n");
        while(r)
        {
            r=r->next;
            s++;
        }
        printf("%d\n",s);
    }
    char dequeue(linkqueue *q,char e)
    {
        node *p;
        if(q->front==q->rear)
            return -1;
        p=q->front->next;
        e=p->data;
        q->front->next=p->next;
        if(q->rear==p)
            q->rear=q->front;
        free(p);
        return e;
    }
    int queueempty(linkqueue *q)
    {
        if(q->front==q->rear)
            return 1;
        else
            return 0;
    }
    void menu()
    {
        printf("           栈队列试验统一界面               \n");
        printf("********************************************\n");
        printf("1 建立栈队列!                              *\n");
        printf("2 栈队列入队操作!                          *\n");
        printf("3 栈队列出队操作!                          *\n");
        printf("4 求栈队列长度!                            *\n");
        printf("5 判断栈队列是否为空!                      *\n");
        printf("6 输出栈队列!                              *\n");
        printf("7 销毁栈队列!                              *\n");
        printf("0 退出!                                    *\n");
        printf("********************************************\n");
    }
    int main(void)
    {
        linkqueue ptr;
        int sel;
        char ch;
        initqueue(&ptr);
        while(1)
        {
            menu();
            printf("please input command:\n");
            scanf("%d",&sel);
            switch(sel)
            {
            case 1:if(yes==1)
                   {
                       printf("此时表已创建!不能再次创建!\n");
                       break;
                   }
                else
                    creatqueue(&ptr);break;
            case 2:if(yes==0)
                   {
                       printf("此时表未创建!不能入队!\n");
                       break;
                   }
                else
                {
                    printf("请输入队的元素值:");
                    scanf("%c",&ch);
                    if((ch=getchar())!='\n')
                        enqueue(&ptr,ch);
                    break;
                }
            case 3:if(yes==0)
                   {
                       printf("此时表为创建!不能出队!\n");
                       break;
                   }
                else
                {
                    ch=dequeue(&ptr,ch);
                    printf("目前出队的元素是%c",ch);
                    break;
                }
            case 4:if(yes==0)
                   {
                       printf("此时链队列未创建!不能求其长度!\n");
                       break;
                   }
                lenqueue(&ptr);
                break;
            case 5:if(yes==0)
                   {
                       printf("此时表未创建!不能判断是否为空!\n");
                       break;
                   }
                else
                {
                    if(queueempty(&ptr))
                        printf("此时队列为空队列!\n");
                    else
                    
                        printf("此时队列为非空队列!\n");
                    
                    break;
                }
            case 6:if(yes==0)
                   {
                       printf("此时栈队列未创建!不能输出!\n");
                       break;
                   }
                           disqueue(&ptr);
                           break;
            case 7:if(yes==0)
                   {
                       printf("此时栈队列未创建!不能销毁!\n");
                       break;
                   }
                destroyqueue(&ptr);
                break;
            case 0:exit(1);break;
            default:printf("输入命令错误!请重新输入:\n");
                break;
            }
        }
        return OK;
    }

   

菜鸟也疯狂
2012-11-03 13:42
梁朝斌
Rank: 4
等 级:业余侠客
帖 子:192
专家分:288
注 册:2012-10-21
收藏
得分:0 
栈队列的所有操作都在这里了啊,慢慢学吧

菜鸟也疯狂
2012-11-03 13:42
一个孩子
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:356
专家分:954
注 册:2012-10-1
收藏
得分:7 
最好自己动手写,多写几遍,以后可能会经常地用到啊

重要的不是结果,是求一个结果的过程,哪怕千难万难,当你有想要的结果时,你已走的很远
2012-11-03 15:18
快速回复:求链队列的一些基本操作
数据加载中...
 
   



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

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