数组实现:
#include
using namespace std;int main()
{
int n,m,s,i=0,j=0,k=0;
cout<<"please input the length of the array:";
cout<<"please input the number of output:";
cin>>m;
int *a=new int[n];
for(i=0;i
a[i]=i+1;
for(i=0;i
{
if(a[i]>0)
{
j++;
{
}
}
s=0;
for(k=0;k
s+=a[k];
break;
}
return 0;
}
链表实现:
#include
using namespace std;
struct ele{
int num;
struct ele * next;
}
main()
{
int n,m,i;
struct ele *h,*u,*p;
cout<<"cin n and m:";
cin>>n>>m;
h=u=new struct ele[];
h->num=1;
for(i=1;i
{
u->next=new struct ele[];
u=u->next;
u->num=i+1;
}
u->next=h;
while(n)
{
for(i=1;i
u=u->next;
p=u->next;
cout<<p->num<<" ";
u->next=p->next;
// delete p;
--n;
}
}