// List.cpp: implementation of the List class.
//
//////////////////////////////////////////////////////////////////////
#include "List.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
List::List(int a[],int n)
{
first=new Node;
first->data=a[0];
first->next=NULL;
Node*p=first;
for(int i=1;i<n;i++)
{
Node*s=new Node;
s->data=a[i];
p->next=s;
p=s;
}
p->next=first;
}
/*void List::Print()
{
Node* p;
p=first;
while(1)
{
cout<<p->data<<"-->";
if(p->next!=first)
p=p->next;
else
break;
}
cout<<endl;
}*/
void List::Delete(int m)
{
int i=1;
Node*p1=first;
Node*p2;
Node*r;
if(m==0)throw"输入有误:";//这边0是bug
else
if(m==1)
{
Node* p;
p=first;
while(1)
{
cout<<p->data<<"-->";
if(p->next!=first)
p=p->next;
else
break;
}
cout<<endl;
}
else
{
while(p1->next!=p1)
{
while(i<m-1)
{
i++;
p1=p1->next;
}
i=1;
p2=p1->next;
r=p2;
cout<<r->data<<"-->";
p1->next=p2->next;
p1=p1->next;
delete r;
}
cout<<p1->data<<endl;;
}
}
List::~List(){}
约瑟夫环 加深链表的理解 应用
需积分: 0 133 浏览量
2008-12-21
18:20:09
上传
评论
收藏 132KB RAR 举报
liyingzai
- 粉丝: 1
- 资源: 13
评论0