#include <iostream>
#include "kudetouwenjian.h"
using namespace std;
int main()
{
linknode *L;
A e=0;
int m,n,c;
cin>>m>>n;
A a[m];
A b[m];
for(int i=0;i<m;i++)
a[i]=i+1;
xunhuanlianbiao(L,a,m);
if(n==1)
{
cout<<m<<endl;
return 0;
}
houzi(L,n,m);
return 0;
}
#include <iostream>
#include <malloc.h>
#include "kudetouwenjian.h"
using namespace std;
void houzi(linknode *&L,int n,int m)
{
linknode *p=L->next;
for(int i=0;i<m-1;i++)
{
for(int a=0;a<n-1;a++)
{
L=p;
p=L->next;
}
L->next=p->next;
free(p);
p=L->next;
}
cout<<L->shuju<<endl;
}
void xunhuanlianbiao(linknode *&L,A a[],int n)
{
linknode *s,*r;
L=(linknode *)malloc(sizeof(linknode));
r=L;
for(int i=0;i<n;i++)
{
s=(linknode *)malloc(sizeof(linknode));
s->shuju=a[i];
r->next=s;
r=s;
}
r->next=L->next;
}
void toucha(linknode *&L,A a[],int n)
{
linknode *s;
L=(linknode *)malloc(sizeof(linknode));
L->next=NULL;
for(int i=0;i<n;i++)
{
s=(linknode *)malloc(sizeof(linknode));
s->shuju=a[i];
s->next=L->next;
L->next=s;
}
}
void shuchu(linknode *L)
{
linknode *p=L->next;
while(p!=NULL)
{
cout<<p->shuju<<" ";
p=p->next;
}
cout<<endl;
}
void weicha(linknode *&L,A a[],int n)
{
linknode *s,*r;
L=(linknode *)malloc(sizeof(linknode));
r=L;
for(int i=0;i<n;i++)
{
s=(linknode *)malloc(sizeof(linknode));
s->shuju=a[i];
r->next=s;
r=s;
}
r->next=NULL;
}
void chushihua(linknode *&L)
{
L=(linknode *)malloc(sizeof(linknode));
L->next=NULL;
}
void cuihui(linknode *&L)
{
linknode * pre=L,* p=L->next;
while(p!=NULL)
{
free(pre);
pre=p;
p=pre->next;
}
free(pre);
L->next=NULL;
}
int panduanshifouweikong(linknode *L)
{
return(L->next==NULL);
}
int changdu(linknode *L)
{
int e=0;
linknode *p=L->next;
while(p!=NULL)
{
e++;
p=p->next;
}
return(e);
}
int shunxuchazhao(linknode * L,int i,A &e)
{
int j=1;
linknode *p=L->next;
if(i<=0)j=j;;
while(j<i)
{
j++;
p=p->next;
}
if(p==NULL)
j=j;
else
{
e=p->shuju;
return(e);
}
}
int chazhaodange(linknode *L,A e)
{
int j=1;
linknode *p=L->next;
if(p==NULL)
return 0;
while(p!=NULL&&e!=p->shuju)
{
p=p->next;
j++;
}
if(p==NULL)
return 0;
else
return(1);
}
bool charudange(linknode *&L,int i,A e)
{
int j=0;
linknode * p=L,* s;
if(i<=0)return false;
while(j<i-1&&p!=NULL)
{
j++;
p=p->next;
}
if(p==NULL)
return false;
else
{
s=(linknode *)malloc(sizeof(linknode));
s->shuju=e;
s->next=p->next;
p->next=s;
}
}
#ifndef KUDETOUWENJIAN_H_INCLUDED
#define KUDETOUWENJIAN_H_INCLUDED
#include <iostream>
typedef int A;
typedef struct lianbiao
{
A shuju;
struct lianbiao *next;
}linknode;
void toucha(linknode *&L,A a[],int n);
void shuchu(linknode *L);
void weicha(linknode *&L,A a[],int n);
void chushihua(linknode *&L);
void cuihui(linknode *&L);
int panduanshifouweikong(linknode *L);
int changdu(linknode *L);
int shunxuchazhao(linknode *L,int i,A &e);
int chazhaodange(linknode *L,A e);
bool charudange(linknode *&L,int i,A e);
void xunhuanlianbiao(linknode *&L,A a[],int n);
void houzi(linknode *&L,int n,int m);
#endif // KUDETOUWENJIAN_H_INCLUDED
第四周 项目4 猴子选大王
最新推荐文章于 2020-11-01 15:24:06 发布