标题:[求助]为什么是死循环-->purana转移-->feng1256转移
取消只看楼主
swr88
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-5-7
 问题点数:0 回复次数:0 
[求助]为什么是死循环-->purana转移-->feng1256转移

#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;
}
哪位高手能帮帮我为什么是死循环

搜索更多相关主题的帖子: purana 
2006-05-07 21:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-62440-1-1.html




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

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