| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1189 人关注过本帖
标题:车厢调度
只看楼主 加入收藏
对林风眠
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2014-12-5
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
车厢调度
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include <conio.h>

#define STACK_INIT_SIZE  100;
#define STACKINCREMENT 10;
typedef char SElemType;
typedef int Status;

int n;//总车厢数
long total=0;

typedef struct //结构体定义
{
    SElemType *base;
    SElemType *top;
    int stacksize;
}SqStack;
//构建一个空栈
Status InitStack(SqStack &S)
{
    S.base=(SElemType*)malloc(STACK_INIT_SIZE*sizeof(SElemType));
    if(!S.base) exit(0);
    S.top=S.base;
    S.stacksize=STACK_INIT_SIZE;
    return 0;
}
//输出栈顶元素
Status GetTop(SqStack &S,SElemType &e)
{
    if(S.top==S.base)
        return 1;
    e= *(S.top-1);
    return 0;
}
Status Full(SqStack &S)
{
    if(S.top-S.base==n)
        return 1;
    return 0;
}
//元素进站
Status Push(SqStack &S,SElemType e)
{
    if(S.top-S.base>=S.stacksize)
    {
        s.base=(SElemType*)realloc(s.base,(STACK_INIT_SIZE+STACKINCRESIZE)*sizeof(SElemType));
        if(!S.base) exit(0);
        S.top=S.base+S.stacksize;
        S.stacksize+=STACKINCREMENT;
    }
    *S.top++=e;
    return 0;
}
//元素出栈
Status Pop(SqStack &S,SElemType &e)
{
    if(S.top==S.base)
        return 1;
    e=*--S.top;
    return 0;
}
//空栈
Status StackEmpty(SqStack &S)
{
    if(S.top==S.base)
        return 1;
    return 0;
}
//构建三个栈进行输出
void f(SqStack &s1,SqStack &s2,SqStack &s3)
{
    int e;
   
         if(!StackEmpty(s1))
         {
             Pop(s1,e);
             Push(s2,e);
             f(s1,s2,s3);
             Pop(s2,e); Push(s1,e);
         }
         if(!StackEmpty(s2))
         {
             Pop(s2,e);Push(s3,e);
             f(s1,s2,s3);
             Pop(s3,e);Push(s2,e);
         }
         if(s3.Full())
         {
             total++;
             s3.print();
         }
}
Status print(SqStack &S)
{
    int *p;
    p=S.base;
    printf("\t[%ld]",total);
    for(;p!=S.top;)
    {
        printf("%d",*p++);
    }
    printf("\n");
}
void main()
{
    SqStack s1,s2,s3;
    printf("请输入车厢的长度");
    InitStack(&s1);
    InitStack(&s2);
    InitStack(&s3);
    for(int i=n;i>1;i--)
        Push(&s1,i);
    f(&s1,&s2,&s3);   
}
--------------------Configuration: he - Win32 Debug--------------------
Compiling...
he.cpp
D:\Users\Administrator\Desktop\he.cpp(24) : error C2143: syntax error : missing ')' before ';'
D:\Users\Administrator\Desktop\he.cpp(24) : error C2059: syntax error : ')'
D:\Users\Administrator\Desktop\he.cpp(24) : error C2100: illegal indirection
D:\Users\Administrator\Desktop\he.cpp(49) : error C2065: 's' : undeclared identifier
D:\Users\Administrator\Desktop\he.cpp(49) : error C2228: left of '.base' must have class/struct/union type
D:\Users\Administrator\Desktop\he.cpp(49) : error C2228: left of '.base' must have class/struct/union type
D:\Users\Administrator\Desktop\he.cpp(49) : error C2143: syntax error : missing ')' before ';'
D:\Users\Administrator\Desktop\he.cpp(49) : error C2143: syntax error : missing ')' before ';'
D:\Users\Administrator\Desktop\he.cpp(49) : error C2065: 'STACKINCRESIZE' : undeclared identifier
D:\Users\Administrator\Desktop\he.cpp(49) : error C2059: syntax error : ')'
D:\Users\Administrator\Desktop\he.cpp(49) : error C2059: syntax error : ')'
D:\Users\Administrator\Desktop\he.cpp(49) : warning C4552: '*' : operator has no effect; expected operator with side-effect
D:\Users\Administrator\Desktop\he.cpp(79) : error C2664: 'Pop' : cannot convert parameter 2 from 'int' to 'char &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(82) : error C2664: 'Pop' : cannot convert parameter 2 from 'int' to 'char &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(86) : error C2664: 'Pop' : cannot convert parameter 2 from 'int' to 'char &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(88) : error C2664: 'Pop' : cannot convert parameter 2 from 'int' to 'char &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(90) : error C2039: 'Full' : is not a member of 'SqStack'
        D:\Users\Administrator\Desktop\he.cpp(16) : see declaration of 'SqStack'
D:\Users\Administrator\Desktop\he.cpp(93) : error C2039: 'print' : is not a member of 'SqStack'
        D:\Users\Administrator\Desktop\he.cpp(16) : see declaration of 'SqStack'
D:\Users\Administrator\Desktop\he.cpp(97) : error C2373: 'print' : redefinition; different type modifiers
D:\Users\Administrator\Desktop\he.cpp(99) : error C2440: '=' : cannot convert from 'char *' to 'int *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\Users\Administrator\Desktop\he.cpp(101) : error C2446: '!=' : no conversion from 'char *' to 'int *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\Users\Administrator\Desktop\he.cpp(101) : error C2230: '!=' : indirection to different types
D:\Users\Administrator\Desktop\he.cpp(111) : error C2664: 'InitStack' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(112) : error C2664: 'InitStack' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(113) : error C2664: 'InitStack' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(115) : error C2664: 'Push' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
D:\Users\Administrator\Desktop\he.cpp(116) : error C2664: 'f' : cannot convert parameter 1 from 'SqStack *' to 'SqStack &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
执行 cl.exe 时出错.

he.exe - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include 结构体 
2014-12-05 23:54
对林风眠
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2014-12-5
收藏
得分:0 
求大神指点,万分感激!
2014-12-05 23:55
巧若拙
Rank: 4
来 自:宁波余姚
等 级:业余侠客
威 望:1
帖 子:159
专家分:273
注 册:2014-8-24
收藏
得分:10 
这么多编译错误,先修改好再说
2014-12-07 20:38
快速回复:车厢调度
数据加载中...
 
   



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

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