找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1690|回复: 4

[求助]为什么是死循环--*purana转移--*feng1256转移

[复制链接]
发表于 2009-11-3 01:47:09 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include <iostream>
#include <string>
using namespace std;
typedef struct node
{
int number;
int password;
struct node *next;
}SLink;
int GetLength(SLink *sq)
{

int i=1;
SLink *p=sq->next;
while(p!=sq)
{
i++;p=p->next;
}
return i;
}
int DelElem(SLink *sq,int i)
{
int j=1;
SLink *p=sq,*q;
if(i<1 || i>GetLength(sq))
return 0;
else if(i==1)
{
if(GetLength(sq)==1)
{q=sq;free(q);
sq=NULL;}
else
{
while(j<GetLength(sq))
{
p=p->next;j++;
}
q=sq;
p->next=q->next;
sq=q->next;
free(q);
return 1;
}
}
else
{
while(j<i-1)
{
p=p->next;j++;
}
q=p->next;
p->next=q->next;
free(q);
return 1;
}
}

void main()
{
int n;
cout << "n=";
cin >> n;
int m;
cout <<"m=";
cin >> m;
SLink *sq ;
SLink *people = (SLink *)malloc(sizeof(SLink));
people->number=1;
cout << "people->password=" ;
cin >> people->password;
people->next=people;
SLink *lq =people;
for(int i=1;i<n;i++)
{
sq =(SLink *)malloc(sizeof(SLink));
sq->number =i+1;
cout <<"sq->password=";
cin >> sq->password;
lq->next =sq;
sq->next =people;
lq = sq;
}
DelElem(people,1);
for(sq=people;sq->next!=people;sq=sq->next)
{

cout << sq->number;
//cout << sq->next;
}
cout << sq->number;
}
哪位高手能帮帮我为什么是死循环
发表于 2009-11-3 01:47:11 | 显示全部楼层 IP:江苏扬州
能不能加点注释,看着就晕!
回复

使用道具 举报

发表于 2009-11-3 01:47:13 | 显示全部楼层 IP:江苏扬州
楼主程序的目标是什么?或说是为了完成什么功能而编的?
回复

使用道具 举报

发表于 2009-11-3 01:47:15 | 显示全部楼层 IP:江苏扬州
这应该到C语言版去...
死循环就是当进入了循环后..就永远不终止地执行下去....
回复

使用道具 举报

发表于 2009-11-3 01:47:17 | 显示全部楼层 IP:江苏扬州
不是死循环
是你while(j<GetLength(sq))
{
p=p->next;j++;
}
q=sq;
p->next=q->next;
sq=q->next;
free(q);//释放了没有把剩下的连接起来,以至后来输出时,输出非法内存空间(对不起,没时间读你代码了,自己把q前面的与后面的连上吧)
return 1;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 07:16 , Processed in 0.329322 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表