嘉定都市网

标题: VC++运行不正常 [打印本页]

作者: 行云流水    时间: 2002-11-10 13:32
标题: VC++运行不正常
我在学校用VC++调试一段程序,结果和书上的一样
但我用家里安装的VC++调试出来就不一样了
同样是一段程序啊,怎么结果不一样呢??
源程序如下:
#include <iostream.h>
#include <stdlib.h>
typedef int ElemType;
struct LNode
{
ElemType data;
LNode *next;
};
void josephus(int n, int m, int s)
{
        LNode *HL=new LNode ;
        HL->next=HL;
        int i,j;
        for(i=n;i>0;i--)
        {
                LNode *newptr= new LNode;
        newptr->data=i;
                newptr->next=HL->next;
                HL->next=newptr;
        }
        LNode *ap=HL,*cp=HL->next;
        for(i=1;i<s;i++)
        {
                ap=cp;
                cp=cp->next;
                if(cp==HL)
                {
                        cp=HL->next;
                    ap=HL;
                }
        }
        for(i=1;i<n;i++)
        {
                for(j=1;j<m;j++)
                {
                    ap=cp;
                    cp=cp->next;
            //cout<<cp->data<<endl;
                    if(cp==HL)
                        {
                           cp=HL->next;
                           ap=HL;
                        }
                }
            cout<<cp->data<<\"      \";
            ap->next=cp->next;
            delete cp;
            cp=ap->next;
                if(cp==HL)
                        {
                           cp=HL->next;
                           ap=HL;
                        }
        }
        cout<<HL->next->data<<endl;
        delete HL->next;
        delete HL;
}
void main()
{int n,m,s;
cout<<\"input three numbers\"<<endl;
cin>>n>>m>>s;
josephus(n,m,s);}

作者: gundam_xx    时间: 2002-11-10 18:23
家里的VC++版本和学校的完全一样吗
.H库里有没有少了什么




欢迎光临 嘉定都市网 (http://www.jiading.com.cn/) Powered by Discuz! X3.1